• Post Reply Bookmark Topic Watch Topic
  • New Topic

Theoretic question: Mutex, Semaphore and Monitor  RSS feed

 
Skripi Mayer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm reading 'Modern Operating Systems' by Tanenbaum and I want to map
the inner process data structures to the java language.

My questions:
Do Semaphores or Mutexes keep track of their callers ?
If i want to implement a Semaphore do I need to store the current executing
Thread in an instance variable of the Semaphore ?

Because if not it might be possible to do:

- Thread1.down();
- Thread2.up(); Thread2.down();

But it is nowhere stated, that a Mutex or Semaphore has an owner or needs to keep track of those.

Which inner Process / inner Thread implementations keep neep / are supposed to keep track of their owner ?
Just a Monitor or Mutex and Semaphores, too ?

Why is a Monitor implementation missing in Java (like java.util.Monitor) ?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every object in Java is a monitor, so monitors are not missing. You don't have to implement a semaphore in Java yourself. There's one included in the java.util.concurrent package available in JDK5. However, if you can't use JDK5, you can download the classes on which the java.util.concurrent package was based from Doug Lea's (author of Concurrent Programming in Java; a very nice read) site...

http://gee.cs.oswego.edu/dl/
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Skripi Mayer:

Do Semaphores or Mutexes keep track of their callers ?

No. That should also take care of most of your other unanswered questions.

Each thread is responsible for ensuring that it decrements a semaphore the same number of times it increments it.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, who is to say that the same thread has to be the one to decrement the semaphore?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!