[MUD-Dev] Re[2]: [MUD-Dev] Multi-threaded mud server.

Travis Casey efindel at io.com
Sun May 30 11:34:31 CEST 1999


On Friday, May 28, 1999, Ross Nicoll wrote:

> On Sun, 16 May 1999, David Bennett wrote:

>> >Semaphores were the original plan, but as I understand it, this would
>> >require a new semaphore for each object. As we're looking at 10,000+
>> >objects, that's a _lot_ of semaphores.
>> Well...  You could do a system that only generated a semphore when it was
>> needed...  As in you have some nice bit you set in the structure for
>> reading/writing and another bit you set for being locked.  Then if it goes
>> to do a normal semphore unlock and it finds that a semaphore is needed it
>> grabs it correctly.  Or just waits on an event or something.
>
> Good idea, but unfortunately it's still possible two processes to
> simultaneously do the check, find no semaphore, and both to then try
> allocating a semaphore, at the same time. Which would just result in a
> mess, really...

That depends on your implementation.  The smart thing to do would be
to set things up so there's a lock on creating semaphores -- only one
thread can create a semaphore at a time.  Better would be a situation
where only one can create a semaphore of a particular *name* at a
time.

Remember -- semaphores aren't a solution to the problem of
simultaneous actions; they're just a nice way to encapsulate a
solution so that others can use it.  The semaphore implementation is
still going to have to rely on blocking interrupts, passing messages,
special CPU instructions, Peterson's method, or whatever.  If you
extend traditional semaphores (e.g., by allowing dynamic creation of
semaphores), you'll have to use such lower-level methods to make sure
that your extensions work.

I recall an implementation used in a textbook in which semaphores were
created when needed... what was done, though, was that when a
process/thread attached to a semaphore, the semaphore library checked
to see whether it existed and, if it didn't, created it.  Since this
was done by the library, it took care of the nasty bits.

--
       |\      _,,,---,,_        Travis S. Casey  <efindel at io.com>
 ZZzz  /,`.-'`'    -.  ;-;;,_   No one agrees with me.  Not even me.
      |,4-  ) )-,_..;\ (  `'-'
     '---''(_/--'  `-'\_)




_______________________________________________
MUD-Dev maillist  -  MUD-Dev at kanga.nu
http://www.kanga.nu/lists/listinfo/mud-dev




More information about the mud-dev-archive mailing list