-
How to create a blocking call for our class?
Hi,
I am trying to create a queue class, with a blocking call for read.
using a read() method or an overloaded >> extraction operator.
I would like my class to behave similar to cin, where it will
wait until there is something in the vector.
I am looking for a method that does not use an additional thread
for polling the vector (queue).
The ones populating this vector (sending signals to this class)
expects nothing more than a lightweight operation on this class
(like pushing a message to the vector)
In short, how to implement a blocking method, which will wait for
data and return with the data, until it encounters an EOF character
(or a terminating pattern string in the vector)
I tried looking out for tying streams to gether.. but nothing worked.
Any help would be appreciated.
Thanks in advance.
Thanks and Regards,
Jose Panakkel
-
It depends very much on your platform. In POSIX systems you'd use signals and alarms, or even spinlocks (if the array is shared by various processes). In Windows you'd use events and event handlers. There is no standard way of accomplishing these tasks -- you have to use your platform's APIs for this.
Danny Kalev
-
Danny,
Thank you very much for the information.
Someone gave a vague idea/thought of an infinite wait on a thread and throwing
an exception into it, to wake it up.. is there any chance this may work?
Can the current thread calling myQueueObject.read() be put to sleep
by the read() method?
Can an exception be thrown into a sleeping thread?
Thanks and Regards,
Jose Panakkel
-
I assume you mean sending a signal to a sleeping thread. Thos should be fine, so long as the platform supports sleeping threads and thread-specific signals. Most POSIX systems nowadays support these features. What you need is a signal handler that will be invoked automatically when a signal is raised.
Last edited by Danny; 04-26-2005 at 05:25 PM.
Danny Kalev
-
Thanks again, Danny..
I will go ahead and do some homework on event handlers.
Any good links or any recommended good site for event handlers in windows
would be a great help..
Thanks again for all the information..
Thanks and Regards,
Jose Panakkel
-
If you're looking for infor about ANSI signals and POSIX signals, here an article that I wrote a couple of years ago:
Danny Kalev
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks