Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » WaitForMultipleObjects() analog?
Re: WaitForMultipleObjects() analog? [message #16135 is a reply to message #16106] Wed, 28 May 2008 22:19 Go to previous messageGo to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

hojtsy wrote on Wed, 28 May 2008 12:16

Mindtraveller,

What are you trying to achieve with multiple Semaphores? I would expect that an alternative implementation could use Monitors. These are fancy mutexes which also have Wait and Pulse methods.
I am working on a U++ example code which uses Monitors to implement a Producer-Consumer queue.

See the concept explained in http://www.albahari.com/threading/part4.html

Hojtsy

I just didn`t fully understand about Monitors usage as we don`t have ones in U++ for now.
Then about waiting a number of Semaphores. Let`s imagine the real world application. Your program must heavily work with a number of devices attached to serial port (or ethernet or something else). Of course it is solved by adding a class which creates new thread and have cycle which is sleeping most of time. But there is a number of awake signal types. And these signals could be activated from within: this thread, OS and main thread. These signals are:
  1. application close event. sleeping i/o thread should do finalization and close.
  2. OS i/o event. sleeping thread should handle the fact of newly sent or received data.
  3. queue event. sleeping thread just got a new task to do. this task was added by another thread.
  4. timer event (timeout). happens when system i/o functions didn`t respond in time or final value of some deferred OS call didn`t arive in time.

These events are dramatically different from each other and when my thread is awakened I should know the type of this event to handle it. So I use one synchronization object (let`s say Semaphore for simplicity) for each event type. Doing this with one Semaphore would be a nightmare, wouldn`t it?
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Interprocess communication with U++
Next Topic: sMutexLock implementation
Goto Forum:
  


Current Time: Wed May 15 13:11:34 CEST 2024

Total time taken to generate the page: 0.02400 seconds