sync: threading.Event -> chan
Starting from e6bea2cf (sync: New package that mirrors Go's sync) there is sync.WaitGroup and it was using threading.Event to signal that waitgroup's counter dropped to zero. threading.Event is implemented in Python's stdlib via threading.Condition, which in turn uses threading.Lock and list of waiters to implement its functionality. Which in turn is very similar to what golang.chan does internally with semaphore and e.g. recv queue. I noticed this while debugging sync test deadlock (see previous patch) and suspecting bug in threading.Event for a moment. While it turned there is no bug in threading.Event, it is better to rely on the common functionality for similar tasks, and pygolang's channel perfectly matches here the need to signal an event. By using our own code instead of stdlib's threading we are likely becoming less bug-prone. This also brings a small speedup: (on i5@1.80GHz) name old time/op new time/op delta workgroup_empty 239µs ± 1% 220µs ± 1% -7.62% (p=0.000 n=10+9) workgroup_raise 275µs ± 2% 264µs ± 2% -3.85% (p=0.000 n=10+10)
Showing
Please register or sign in to comment