Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

semaphores

 
Tumisang Montsho
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do problems arise if two or more processes can access a semaphore concurrently?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4402
251
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If such problems happens, that is not something where you should use semaphore on. If you need more helpful answer, can you elaborate your question a little more?
 
Henry Wong
author
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To elaborate some more, Java has a semaphore class -- the java.util.concurrent.Semaphore class -- and instances of it can't be accessed from outside the JVM. Actually, instances of any class can't be directly accessed outside of the JVM, and hence, can't be share between processes.

Henry
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4402
251
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:... and hence, can't be share between processes.

Ah! I was misinterpreting that as sharing between threads. Sorry
 
Tumisang Montsho
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK guys! a bit of elaboration guys, one important application of semaphores is in the enforcement of mutual exclusion but processes using a semaphore must themselves access the semaphore under mutual exclusion. with reference to the operations on semaphores why might problems arise if two or more processes can access a semaphore concurrently.
 
Henry Wong
author
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tumisang Montsho wrote:OK guys! a bit of elaboration guys, one important application of semaphores is in the enforcement of mutual exclusion but processes using a semaphore must themselves access the semaphore under mutual exclusion. with reference to the operations on semaphores why might problems arise if two or more processes can access a semaphore concurrently.



You *really* need to get your terminology correct. Threads and processes are *not* the same thing. Also. I can't tell which semaphore you are referring to. We have been assuming that you are referring to the semaphore class in the java library (after all, this is a java site), but your other topic seems to imply that you are talking about about the UNIX IPC mechanism.

So, which is it? processes or threads? core library or UNIX IPC?

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic