Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi all, I have a multithreading issue I cannot find a good answer for,

I have a majority of my code in a dll that I have made to support my program, it creates threads in its internal objects. The client application creates a few as well.

Are these threads all created in the same process or does the dll create its own process. I don't make any calls to CreateProcess either.

The reason for this question is I want to use critical sections between my dll and app as research has revealed that mutexes can use up to 600 cycles per lock on some architectures.

This may seem like a stupid question to some but I have limited access to the internet and texts, also I have written many lines of code on an assumption only to have the umption shoved up my ***. So i feel its better to be umption free than sorry.

cheers.
Posted

A dll used is normally "in-process" and therefore you could use critical sections. This would not apply if it would be a COM server dll that you use. In that case it would be "out-of-process" and you should use a mutex instead.

Good luck!
 
Share this answer
 
Comments
chris4562 22-Dec-10 12:03pm    
Cheers, thats what I thaught, my other approach was to use boolean or smaller values to do 'atomic' syncronisation but it seems many systems may not write words in one cycle which is interesting as a uni lecturer once told me it was safe on x86 machines.
E.F. Nijboer 22-Dec-10 13:00pm    
Using a boolean could work if you implement the assembly for compare and exchange yourself (CMPXCHG). Also, there are lock free synchronization schemes but they don't give guarantees concerning out-of-order execution.
Harrison H 23-Dec-10 14:27pm    
I've heard of schemes that are supposedly pretty portable (running on multiple, multiple, mobile platforms) that use two boolean values (and obviously no assembly)
E.F. Nijboer 24-Dec-10 4:14am    
But how could that be thread safe? because reading the boolean value and writing it are two separate actions and a second processor could change the value in between the two.
if(!bSync)
{
# read or write of another processor at this point could cause unexpected results #
bSync = true;
}
Pretty sure the DLL is loaded into the application process and all threads are created within that

Download Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653[^] and you can browse the threads your process has created (invaluable tool if you don't have it anyway!)



Edit: Was just about to add about 'in process' and 'out of process' (i remember from my VB6 days!), but been beaten to it.
 
Share this answer
 
v2
Comments
chris4562 22-Dec-10 12:11pm    
VB6 was great that was what I started with, then I moved to C++ and people call it the lazy programmers language... yeah right. That process explorer was useful I could see my threads in one process and directx in the other, would have answered my question also. cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900