Thanks,
Vic
They are not thread-safe. Gate access to the data structures using a mutex
semaphore, or better yet - derive a class from CMap etc and hide the mutex
code with your class
Victor Silva <inv...@email.address> wrote in article
<01bc0889$6b163310$bc941ace@silv>...
> Are the MFC CArray, CMap and CList classes thread safe (i.e. must I
> implement a mutex area when one thread adds to a CMap and
> another thread removes from the same CMap?)
>
> Thanks,
> Vic
>
To keep MFC classes efficient their designers have decided not to
thread-protect them at the object level but at the class level. It's a very
good choice. If YOU want to use a map, YOU must synchronize accesses. For
that you can either use a CSingleLock Object or a Critical Section. They
are lightweight. A Mutex or a Semaphore is rather hammer-like objects for
your case.
I don't recommend to subclass a CArray for bug and performance reasons...
If you really want to encapsulate the lock use aggregation rather. Create a
new CMyArray that contain a ptr to a CArray...
Hope it helps
-------------------------------------
Regis NICOLAS - Smartcode Technologie
R&D Windows
http://www.smartcode.fr/
http://www.smartcodesoft.com/
mailto:nic...@smartcode.fr
Tel.: (33) (0)4 67 59 30 16