busy waiting


Author: yifei / Created: July 28, 2017, 7:34 a.m. / Modified: July 28, 2017, 3:35 p.m. / Edit

while True: pass

this is busy waiting

while True: time.sleep(10)

this is not busy waiting, bucause cpu are free to do other things, and only need trivial cpu cycles

http://stackoverflow.com/questions/529034/python-pass-or-sleep-for-long-running-processes

busy waiting is considered as anti-pattern, but using it in spinning-lock is ok

should use select if we need to wait for something

https://en.wikipedia.org/wiki/Busy_waiting


评论区