• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Theoretic question: Mutex, Semaphore and Monitor

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ?
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, who is to say that the same thread has to be the one to decrement the semaphore?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic