Thread: Help on waitforsingleobject(.....)

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    4

    Help on waitforsingleobject(.....)

    Hi All,

    Can two threads wait for an event to be signalled by a 3rd thread?

    thread1 is on waitforsingleobject(....., eventobj3, .....)
    thread2 is on waitforsingleobject(....., eventobj3, .....)



    thread3 finishes its task and calls a setevent(eventobj3),

    what will happen now? will both thread1 and thread2 get the signal?

    Please guide me on this.

    Thanks,
    raj.

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    It depends on how the event object is created.

    If the event is a manual reset event, then when the event is in a signaled state, any and all threads are released from wait, and any subsequent threads that attempt to wait will not be blocked, until such time that the event is reset to a non-signaled state. Think traffic light.

    If the event is an auto-reset event, then only one thread will be released (though I'm not certain there's a particular order to a queue, there may be a FIFO queue). The event is reset to non-signaled when that one waiting thread is released, and any other threads there were waiting continue to wait until the event is once again signaled. Think security gate (one car at a time).

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There's no guaranteed order for released threads. Although there is actually a FIFO, there are circumstances in which a thread may lose its place in the queue and get back to the end of line.

    That said, this is a Win32 question.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with WaitForSingleObject
    By Anddos in forum Windows Programming
    Replies: 5
    Last Post: 12-03-2006, 06:48 PM
  2. WaitForSingleObject does not allocating...
    By Devil Panther in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2006, 03:49 AM
  3. Passing HWND of edit box to thread?
    By berto in forum Windows Programming
    Replies: 8
    Last Post: 06-07-2003, 04:43 PM