How to create a blocking call for our class?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: How to create a blocking call for our class?

  1. #1
    Join Date
    Apr 2005
    Posts
    3

    Smile 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

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    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

  3. #3
    Join Date
    Apr 2005
    Posts
    3
    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

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    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 06:25 PM.
    Danny Kalev

  5. #5
    Join Date
    Apr 2005
    Posts
    3
    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

  6. #6
    Join Date
    Nov 2003
    Posts
    4,118
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center