[Q][Unix][Sockets] Looking for explainations of 3 semaphores and error states.

Lex Spoon lex at cc.gatech.edu
Mon Jul 24 16:02:00 UTC 2000


"Peter Crowther" <peter at crowther.demon.co.uk> wrote:
> > From: Lex Spoon [mailto:lex at cc.gatech.edu]
> > John M McIntosh <johnmci at smalltalkconsulting.com> wrote:
> > > You have thread (A) that reads data from a socket, and
> > > thread (B) that writes data to the same socket.
> > > Thread (A) waits on read with Sempahore X
> > > then thread (B) happens to wait on write on Semaphore X.
> >
> > First, why would you have a threading
> > situation like this in practice?
> 
> Consider a multi-user game with Squeak as the server [for those that know
> me, the example won't be a surprise].  Each user connection has a thread
> that handles input, waiting until input appears on a socket.  When that
> input forms a complete command, the thread executes the command.  This may
> involve sending output to other users with their own connections.  At that
> point, you might have exactly the scenario described on another user's
> connection if that user happens not to be typing at the time.
> 
> For multi-user game, replace with pretty much any multi-threaded server
> where input on one socket might trigger output on another.
> 

Where, in this example, are two threads touching the *same* socket?  The
original scheme already had 1 semaphore per socket.  The issue is if one
thread accidentally gobbles events intended for another thread, and that
seems, at the least, easy to avoid.  More than the least, it would seem
uncommon, but then I'm more of a theoretician when it comes to network
programming....


-Lex





More information about the Squeak-dev mailing list