Re: Implementing Java like synchronization with the OS/2 API in C++
- From: "William L. Hartzell" <wlhartzell@xxxxxxxxxxx>
- Date: Mon, 26 Dec 2005 07:50:57 -0600
Sir:
Marcel Müller wrote:
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.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?
-- Bill Thanks a Million! .
- Follow-Ups:
- Re: Implementing Java like synchronization with the OS/2 API in C++
- From: Marcel Müller
- Re: Implementing Java like synchronization with the OS/2 API in C++
- References:
- Implementing Java like synchronization with the OS/2 API in C++
- From: Marcel Müller
- Implementing Java like synchronization with the OS/2 API in C++
- Prev by Date: Implementing Java like synchronization with the OS/2 API in C++
- Next by Date: Re: Implementing Java like synchronization with the OS/2 API in C++
- Previous by thread: Implementing Java like synchronization with the OS/2 API in C++
- Next by thread: Re: Implementing Java like synchronization with the OS/2 API in C++
- Index(es):
Relevant Pages
|