java - Bounded buffer, order of mutex vs empty. which comes first -


In the limited buffer problem shown in the book, I have a question about the command of Sackphars (muxtex, blank), "operating system concepts" by gagne has two images of the code below i

first) Buffer

Second) insert method.

My question is: what is the reason for being empty .acquire () mutex.acquire () in the insert method? Is not it more clear if the mute x Aquarius () comes before empty. I know about the functionality, the order does not matter, but is there any reason why the author Mute X Empty before the Aqua Where does the aquire say?

Enter image details here

The order is important for that case when the buffer is completed. The effect of blocking the thread is empty.quaver () , there is not at least one free slot in the buffer before attempting to add an item to the buffer.

If reversed, the function will look like this:

  Enter the public Zero (object item) {mutex.acquire (); Empty.acquire (); ...  

This method is called when buffer is complete, then received mutex while blocking the thread on empty.acquire () . Then, if any other thread calls remove () to clear a buffer slot, it will be blocked on mutex.acquire () . Now, no new element can be added, because the buffer is full and all attempts to remove the object will be blocked.


Comments

Popular posts from this blog

c# - Highlight all words containing a letter in a richtextbox -

Editing Python Class in Shell and SQLAlchemy -

java - JavaFX WebEngine Video Playback in Linux -