troubleshooting Question

using semaphores to synchronize threads in java

Avatar of blossompark
blossomparkFlag for Ireland asked on
11 Comments1 Solution449 ViewsLast Modified:
      I have a very simple application (see attached file) which is supposed to alternatively print  to screen;
TA going first!
TB going second!
TA going first!
TB going second!

until the process is interrupted....
i'm using 2 threads and a semaphore to synchronize thread execution, however when i put a for loop in main to show  the output as above, the output is not consistently alternating between statements as i expected.
When i comment out  the loop (currently commented out) the statements alternate as expected.
can someone have a look at  my code and see if they can highlight   the problem? Or have i misunderstood semaphores entirely?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros