Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CMap, CList, CArray Thread safe?

730 views
Skip to first unread message

Victor Silva

unread,
Jan 22, 1997, 3:00:00 AM1/22/97
to

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

Todd Whitmore

unread,
Jan 22, 1997, 3:00:00 AM1/22/97
to

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?)

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


Dave Steckler

unread,
Jan 22, 1997, 3:00:00 AM1/22/97
to

No, they are not threadsafe. You can checkout \msdev\mfc\include\afxtempl.h
yourself on issues like this, btw. :-)

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
>

Regis NICOLAS

unread,
Jan 23, 1997, 3:00:00 AM1/23/97
to

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


0 new messages