忙等待

“`
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

About 逸飞

后端工程师

发表评论

电子邮件地址不会被公开。 必填项已用*标注