Only one thread accessing the CList object
-
I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh
-
I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh
I'm sorry but time is not my friend right now to make an example, but you can start searching for this on MSDN: CMutex or CCriticalSection. Hope this helps. PS: if you have installed the MSDN Help from Visual Studio.NET then use this address: ms-help://MS.VSCC/MS.MSDNVS/vccore/html/_core_Multithreading.3a_.How_to_Use_the_Synchronization_Classes.htm Andres Manggini. Buenos Aires - Argentina.
-
I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh
You should use something like this:
CCriticalSection cs; // this object must be global of static in your class
// then in the function that access the CList
void CMyClass::FunctionThatAccessTheCList ()
{
// lock this section, begins the synchronized section
cs.Lock ();
//.... modify the list herecs.Unlock ();
// end synchronized section
}Best regards, Alexandru Savescu
-
I want a sample program to create two threads & only one thread access the CList object at a time. that is, one thread uses some(i don't know which) synchronization object to lock the CList object & writes to it and then releases the CList object. Next another thread does the same process, but instead of writing, it reads from the CList. can anybody help? Rsh
This post of mine explains a convenient approach to synchronizing access to a data structure. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
This post of mine explains a convenient approach to synchronizing access to a data structure. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
You should use something like this:
CCriticalSection cs; // this object must be global of static in your class
// then in the function that access the CList
void CMyClass::FunctionThatAccessTheCList ()
{
// lock this section, begins the synchronized section
cs.Lock ();
//.... modify the list herecs.Unlock ();
// end synchronized section
}Best regards, Alexandru Savescu