WaitForSingleObject() with Multiple threads

WaitForSingleObject() with Multiple threads

Post by Someon » Fri, 16 Jul 1999 04:00:00



If I create an event, and there are more than 1 thread waiting on that
event, once the event handle is signaled, all threads return from the
WaitForSingleObject() call.  Is there a way to make it so only 1 thread
returns?  I'm running on NT4.
 
 
 

WaitForSingleObject() with Multiple threads

Post by Jon Sturge » Fri, 16 Jul 1999 04:00:00




Quote:>If I create an event, and there are more than 1 thread waiting on that
>event, once the event handle is signaled, all threads return from the
>WaitForSingleObject() call.  Is there a way to make it so only 1 thread
>returns?  I'm running on NT4.

You're obviously using a manual-reset event object.  To obtain the
functionality you desire, use an auto-reset event object instead.  See the
documentation for CreateEvent() for a (brief) description of the
difference.

A manual-reset event object will release *all* threads waiting on that
object when it becomes signaled.  The event object remains signaled until
reset by calling the ResetEvent() function.

An auto-reset event object will release *only one* thread waiting on that
object when it becomes signaled.  The kernel automatically resets the event
after releasing one of the threads waiting on the object.  You have no
control (other than the priority of the waiting threads) over which thread
will be released if several are waiting.

See Richter's excellent "Advanced Windows, 3rd Edition" by Microsoft Press,
ISBN 1-57231-548-2, Chapter 10 for further discussion.

Regards,
Jon Sturgeon


 
 
 

1. multiple processes & multiple threads program has advantage over one process & multiple threads program ?

for example, when implementing a FTP server, one optioins is to make
it multiple processes and each process creates multiple threads;
Option 2 is to use ONLY one process but create the same number of
total threads as the options 1.

Which option has better performance ?

I think the options 2 is better since process spawning is more
expensive.

So go further, what is the point to use fork() when we have multple
threads ?

Any comments are appreciated.

shanyou

2. FBI WANTS Info on the Worm

3. Multiple GraphBuilders, Multiple Threads?

4. Do all lines get "double-spaced" in FrontPage Express?

5. Hangup if multiple threads access multiple Exchange mailboxes

6. Recommendations for Time tracking software?

7. WaitForSingleObject does't wait for thread handle

8. projects

9. WaitForSingleObject prevents thread function from executing?

10. WaitForSingleObject on thread handle locks on win2000

11. WaitForSingleObject prevents thread function from executing?

12. Basic POSIX threads question - multiple concurrent threads