Welcome, Guest. Please login or register.

Author Topic: Semaphores...  (Read 3181 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline CrazyProg

  • Newbie
  • *
  • Join Date: Oct 2004
  • Posts: 14
    • Show all replies
Re: Semaphores...
« on: November 08, 2005, 12:00:50 AM »
Could you work it with two semaphores.

Semaphore (a) is always gotten with AttemptSemaphoreShared() except by the destructor method, witch does an ObtainSemaphore().

Semaphore (b) is the used for locking purposes.

All the methods lock (a) the lock (b) then free the lock on (a)

For most methods an AttemptSemaphoreShared() on (a) will succeed, if it doesn't then someone is running the destructor().

 

Offline CrazyProg

  • Newbie
  • *
  • Join Date: Oct 2004
  • Posts: 14
    • Show all replies
Re: Semaphores...
« Reply #1 on: November 08, 2005, 12:28:53 AM »
Your main problem is controlling what is accessing your methods when you want to run the destructor, and of course avoiding race conditions.  Using a private semaphore within your methods to do this will work.  This is done with libraries/devices all the time.  :-)

Quote

Finally, SignalSemaphores are quite large structures, one is really quite enough to allocate ;-)


As for a SignalSemaphore being large it is only 46 bytes.