File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes semaphores Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "semaphores" Watch "semaphores" New topic
Author

semaphores

Tumisang Montsho
Greenhorn

Joined: Nov 30, 2011
Posts: 3
why do problems arise if two or more processes can access a semaphore concurrently?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3090
    
  40

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?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3090
    
  40

Henry Wong wrote:... and hence, can't be share between processes.

Ah! I was misinterpreting that as sharing between threads. Sorry
Tumisang Montsho
Greenhorn

Joined: Nov 30, 2011
Posts: 3
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
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: semaphores