Using CriticalSections and Components
-
Hi have a quick question(hopefully). I've got a multithreaded ATL component for dealing with RAS. I've been told I should put CriticalSections around certain areas of the system. My container application creates 8 instances of the Component and each instance creates 2 child threads. Do I need some form of parent Container to put in a CriticalSection, or do I put the criticalsection in each instances constructor/destructor.
-
Hi have a quick question(hopefully). I've got a multithreaded ATL component for dealing with RAS. I've been told I should put CriticalSections around certain areas of the system. My container application creates 8 instances of the Component and each instance creates 2 child threads. Do I need some form of parent Container to put in a CriticalSection, or do I put the criticalsection in each instances constructor/destructor.
It is less simple than that. You need to put Enter/LeaveCritSect's around access to shared resources. If each of your instances are independent, then you don't need any critical sections. You may need CritSects in the sub-threads if they can collide when accesses common resources. So the general answer is "it depends". The fewer CriticalSections you have the better as it means your components will run that little bit more smoothly, especially on multi-threaded systems. But it is more important to be safe. I hope this sort-of-helps. Iain.