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



Sir:

Marcel Müller wrote:
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?


Why not use a listener model and the publish/subscribe model. The listener thread would subscribe to the monitor thread and block waiting to be notified. The monitor thread would keep a list of handles TID/PIDs to notify and post the event when it happens. Mutex Semaphores would not be needed. Then the class that has the subscriber/listener thread can be aggregated as an attribute of the class that needs the event, no multi-inheritances. The monitor thread can be in a class that could even be in another program object. Been shown to be easier to debug.

--
Bill
Thanks a Million!
.



Relevant Pages

  • Implementing Java like synchronization with the OS/2 API in C++
    ... But I did not succeed in the second part, the notification logic. ... The notifyallfunction wakes us all threads waiting on this instance. ... needs to release the mutex semaphore while waiting for the notification ... So I have to wait for an event semaphore and a ...
    (comp.os.os2.programmer.misc)
  • Re: B&H Now Has the Nikon 18-200
    ... If it's 10 people and 8 lenses, ... does make sense to notify them all, but at *some* point it seems to me ... on the notification list, ... Right now the "Notify" option is disabled for the Nikon D200. ...
    (rec.photo.digital.slr-systems)
  • Re: Mobile Service & Auto Start
    ... Check the Notify class. ... /// This Notification sample uses the Notification Manager in Windows CE.NET ... private OpenNETCF.Windows.Forms.GroupBox groupBox1; ... private void InitializeComponent() ...
    (microsoft.public.dotnet.framework.compactframework)
  • 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: Mobile Service & Auto Start
    ... Check the Notify class. ... /// This Notification sample uses the Notification Manager in Windows CE.NET ... private OpenNETCF.Windows.Forms.GroupBox groupBox1; ... private void InitializeComponent() ...
    (microsoft.public.dotnet.framework.compactframework)