Implementing Java like synchronization with the OS/2 API in C++



Hi,

I am currenly trying to implement the notification semantic like
java.lang.Object in C++ using the OS/2 API. Since C++ does not have an
Object base class but multiple inheritance I wrote a class which adds
the functionality to any other class by simply inheriting from it.

The first part, synchronized objects, is trivial. DosCreateMutexSem and
so on do their job pretty well.
But I did not succeed in the second part, the notification logic.

The notification should work as follows:

The wait() function waits for a notification signal.
The notify() funtion wakes up a single thread waition on wait (if any).
The notifyall() function wakes us all threads waiting on this instance.

Additionally all of these functions must be called while the current
thread owns the mutex semaphore associated with this object
(synchronized context). And of course they must return in synchronized
context too. So in fact notifyall() will wake up the threads one by one,
always waiting for the previous thread to release the mutex.

Here comes the problem. To make this useful the wait() implementation
needs to release the mutex semaphore while waiting for the notification
event. But once it receives a signal, it needs to aquire the mutex back
in an atomic operation. So I have to wait for an event semaphore and a
mutex semaphore simultaniously. Unfortunately Muxwait semaphores do not
allow a mixture of mutex and event semaphores.

Any ideas how to implement this behavior using the native OS/2 semaphores?


Marcel .



Relevant Pages

  • Re: Implementing Java like synchronization with the OS/2 API in C++
    ... I am currenly trying to implement the notification semantic like ... notifyallfunction wakes us all threads waiting on this instance. ... Additionally all of these functions must be called while the current thread owns the mutex semaphore associated with this object. ... The monitor thread would keep a list of handles TID/PIDs to notify and post the event when it happens. ...
    (comp.os.os2.programmer.misc)
  • Re: A little threading problem
    ... > forever (because it doesn't get notified, because the notification ... > already happened), waiting to be notified from the main thread, and the ... T-B: released mainCond ... As for what I'm trying to do; I'm trying to merge three huge XML files ...
    (comp.lang.python)
  • Re: hang playing video...
    ... Obviously this notification is never occurring so the only ... The filter graph manager will be waiting for 2 of these one for each ... DeliverEndOfStream() call, I call m_pOutputQueue->EOS. ... easy to get caught in a CAutoLock deadlock. ...
    (microsoft.public.win32.programmer.directx.audio)
  • Re: can not get phone calls
    ... To summarize, you have a single phone line with the Call Waiting service, ... call and putting the Internet "on hold". ... internet connection, but I doubt that ordinary Call Waiting from your phone ... > used to get phone calls notification on the screen until Jan.05 then I got ...
    (microsoft.public.windowsxp.general)