Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

WaitForSingleObject blocking

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ramialhasan - 18 May 2005 15:44 GMT
If I have some c++ class exported from a Win32 dll, and from some other
console application I created two threads and each thread creates an
instance of the exported class.

My question is related to using WaitForSingleObject from within the dll
class methods and if the two threads called a method in the dll that
blocks on WaitForSingleObject for a long time, then are the two
instances waiting for each other or if returned from
WaitForSingleObject it can continue event if the other thread still
blocked on its instance?

Thanks
Rami
Doug Harrison [MVP] - 18 May 2005 16:37 GMT
> If I have some c++ class exported from a Win32 dll, and from some other
> console application I created two threads and each thread creates an
[quoted text clipped - 6 lines]
> WaitForSingleObject it can continue event if the other thread still
> blocked on its instance?

The threads wait on the object referred to by the HANDLE that you passed to
WFSO to become signaled or for the timeout interval you specified to
expire. Exactly what happens when the handle becomes signaled depends on
the type of the sync object. For example, only one thread is allowed to
acquire a mutex and progress, while the rest remain blocked (modulo
non-INFINITE timeout values) until that thread releases it (or terminates,
in which case it "abandons" the mutex), at which point, another thread can
acquire the mutex.

Signature

Doug Harrison
Microsoft MVP - Visual C++

ramialhasan - 18 May 2005 21:34 GMT
Sorry but I mean that the two threads are calling the same method but
from different instances and each instance has its own copy of the sync
object. so they are not waiting on the same event but on different
evemts. But my question is related to DLL processing, so if one thread
is waiting on its own event is the other instances blocked two until
the waiting is released or each thread runs in its own processing
thread?
Regards,
Rami
Scott McPhillips [MVP] - 18 May 2005 22:26 GMT
> Sorry but I mean that the two threads are calling the same method but
> from different instances and each instance has its own copy of the sync
[quoted text clipped - 5 lines]
> Regards,
> Rami

Each thread runs independently.  If each thread is using a different
sync object they do not affect each other.

Signature

Scott McPhillips [VC++ MVP]

Doug Harrison [MVP] - 18 May 2005 23:47 GMT
> Sorry but I mean that the two threads are calling the same method but
> from different instances and each instance has its own copy of the sync
[quoted text clipped - 3 lines]
> the waiting is released or each thread runs in its own processing
> thread?

I'm not sure what you think is special about DLLs. They're pretty much just
chunks of code and data loaded into your process's address space, though
the system does serialize the execution of DllMain functions. As for your
sync objects, if the HANDLEs you pass to WFSO refer to different sync
objects, no synchronization occurs between the two threads when they call
WFSO on their respective HANDLEs. They run independently of one another.

Signature

Doug Harrison
Microsoft MVP - Visual C++

ramialhasan - 19 May 2005 16:06 GMT
Thanks for you all, now this is clear

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.