What does select(2) do if you close(2) a file descriptor in a separate thread?

前端 未结 4 1533
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 09:53

What is the behavior of the select(2) function when a file descriptor it is watching for reading is closed by another thread?

From some cursory testing,

4条回答
  •  無奈伤痛
    2020-12-03 10:49

    It's a little confusing what you're asking...

    Select() should return upon an "interesting" change. If the close() merely decremented the reference count and the file was still open for writing somewhere then there's no reason for select() to wake up.

    If the other thread did close() on the only open descriptor then it gets more interesting, but I'd need to see a simple version of the code to see if something's really wrong.

提交回复
热议问题