Create a thread & use mutex for synchronization
-
I want to create two threads. One thread should write to the CLidt object and the other thread should read from the CList object.And i want to use Mutex as the synchronization object, so that only one thread can access the CList object at a time. Pls. help Rsh
-
I want to create two threads. One thread should write to the CLidt object and the other thread should read from the CList object.And i want to use Mutex as the synchronization object, so that only one thread can access the CList object at a time. Pls. help Rsh
Actually a critical section is a better sync object for your purposes, and easier to use. Each thread calls EnterCriticalSection() before accessing the list, then LeaveCriticalSection() once it's done with the list. --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
Actually a critical section is a better sync object for your purposes, and easier to use. Each thread calls EnterCriticalSection() before accessing the list, then LeaveCriticalSection() once it's done with the list. --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
Just out of interest, why is critical section better in this case? Wouldn't mutex serve the same purpose? Regards, wilche
A critical section is more lightweight than a mutex. A mutex differs from a critical section in it can be accessed across process boundaries and you can specify a timeout when waiting on it. Neither of these are needed in his situation so might as well use a critical section.
-
Just out of interest, why is critical section better in this case? Wouldn't mutex serve the same purpose? Regards, wilche
The technical reason is that a critical section doesn't require a switch to kernel mode unless a second thread is trying to lock it when another already has the lock. A mutex will always cause a kernel mode switch. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?