Mutex lock: what does “blocking” mean?

后端 未结 4 530
日久生厌
日久生厌 2020-12-28 16:15

I\'ve been reading up on multithreading and shared resources access and one of the many (for me) new concepts is the mutex lock. What I can\'t seem to find out is what is ac

4条回答
  •  别那么骄傲
    2020-12-28 16:32

    The simplest way to think of it is that the blocked thread is put in a wait ("sleeping") state until the mutex is released by the thread holding it. At that point the operating system will "wake up" one of the threads waiting on the mutex and let it acquire it and continue. It's as if the OS simply puts the blocked thread on a shelf until it has the thing it needs to continue. Until the OS takes the thread off the shelf, it's not doing anything. The exact implementation -- which thread gets to go next, whether they all get woken up or they're queued -- will depend on your OS and what language/framework you are using.

提交回复
热议问题