Deepak Bala wrote:
Now, if you ever come across a situation where incrementing / decrementing counters need to be thread safe across multiple threads, I would suggest the use of atomic variables. They simplify this process greatly.
http://docs.oracle.com/javase/tutorial/essential/concurrency/atomicvars.html
Stephan van Hulst wrote:If a client with some IP address connects to a server on a specific port, a socket is created. If the same IP address does this again, it will fail because the socket already exists.
If another IP address connects to the same port, it will create a different socket. But this is no different from handling separate requests on different ports.
Harsha Smith wrote:without semaphore, cyclic barrier, the following code produced desired result for several runs.
naved momin wrote:
John Vorwald wrote:Try a semaphore with one permit, look for producer / consumer examples...
sebastian aguirre wrote:but the variable is something that is created and remains more time occupying memory so I'm not sure.