ThreadPool.RegisterWaitForSingleObject

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The MSDN documentation for this states:

The wait thread uses the Win32 WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system handle in multiple calls to RegisterWaitForSingleObject, you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to RegisterWaitForSingleObject, because the wait thread might not detect that the event is signaled before it is reset.

My question is what constitutes a "native operating system handle". If I call ThreadPool.RegisterWaitForSingleObject twice each time with the same ManualResetEvent does this constitute using the "same native operating system handle"?

Just trying to avoid problems with my code in the future.

Thanks,


- Chris Tanger
 
Hi Chris,

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Hi Chris,

As the document said, here "native operating system handle" means the
handle which will be taken by the WaitForMultipleObjects API.

The WaitForMultipleObjects function can specify handles of any of the
following object types in the lpHandles array:
Change notification
Console input
Event
Job
Memory resource notification
Mutex
Process
Semaphore
Thread
Waitable timer

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/waitformultipleobjects.asp

In dotnet framework, we use some of them
System.Threading.WaitHandle
System.Threading.AutoResetEvent
System.Threading.ManualResetEvent
System.Threading.Mutex

All the dotnet synchronized object is the encapsulation of the unmanaged
object for Event ,Mutex.
My question is what constitutes a "native operating system handle". If I
call ThreadPool.RegisterWaitForSingleObject twice each time with the same
ManualResetEvent does this constitute using the "same native operating
system handle"?
If we call the RegisterWaitForSingleObject with same ManualResetEvent
twice, the twice will be using the same native operation system handle.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I'll have to be very careful. It looks like on Windows 95/98/ME even
duplication of the handle using DuplicateHandle is not allowed. I don't
care too much about the obsolete windows architectures though.

Thanks,

-Chris Tanger
 
I believe I am using the same ManualResetEvent simultaneously in two
calls to RegisterWaitForSingleObject now, I have never received any
exceptions because of it. My guess is that this is a dangerous situation
because there may be not indication that anything is wrong until some event
doesn't get properly processed, is this true?

-Chris Tanger
 
Hi Chris,

I think this is due to how you implement your application, there may be
certain situation that two threads are waiting for one event. Once the
event occur, the two threads will be awaked.
e.g. one writing thread is running to append content to a file when the
other reading threads(more than one) will be blocked until the writing
thread is finished. And now the reading threads will start to do the
reading operation in the same time because the reading can be shared.

So the design is to make the application design more flexible. If you do
not want, I think you may need to declare two different events for
synchronized.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top