Article View: comp.sys.mac.programmer.codewarrior
Article #1399Re: MP-safe MSL/new()
From: Howard Hinnant
Date: Thu, 05 Oct 2000 00:00
Date: Thu, 05 Oct 2000 00:00
46 lines
2917 bytes
2917 bytes
In article
<karsten.loeffler-7D396D.15575505102000@newsserv.uni-tuebingen.de>,
Karsten Loeffler <karsten.loeffler@uni-tuebingen.de> wrote:
| Are there plans at Metrowerks to make the MSL - especially the 'MSL
| C++.PPC.Lib' - MP-safe?
| That means, to use MPAllocateAligned(...) in the operator new() methods.
Yes, there are plans to migrate to use of the MPxxx calls. Note that this
will break compatibility with earlier Mac OS's, so it will first probably
be offered as an option.
However, there is really no need for you to wait. In the shipping
configuration, new simply forwards to malloc. And malloc has a single
entry point into the OS in pool_alloc.mac.c: __sys_alloc and __sys_free.
You can simply substitute calls to the MPxxx functions and recompile the C
lib.
You should also #define _MWMT 1 in <ansi_prefix.mac.h> and recompile the C
and C++ libs. This will protect the pooling that malloc does with calls
to MPEnterCriticalRegion, etc. This will also put a mutex object in
std::string to protect two threads from simultaneously fooling with a
string's refcount. This may degrade performance. An alternative
std::string implementation is available without refcounting (and mutexes)
with #define _MSL_NO_REFCOUNT_STRING in <mslconfig> (requires a C++ lib
recompile).
Please note that the C++ lib is designed to be "level 1" thread safe. That is:
1. It is safe to simultaneously call const and non-const
methods from different threads to distinct objects.
2. It is safe to simultaneously call const methods, and
methods otherwise guaranteed not to alter the state
of an object (or invalidate outstanding references and
iterators of a container) from different threads to
the same object.
3. It is not safe for different threads to simultaneously
access the same object when at least one thread calls
non-const methods, or methods that invalidate outstanding
references or iterators to the object. The programmer is
responsible for using thread synchronization primitives
(e.g. mutex) to avoid such situations.
-Howard
Technical Details
Message-ID:
<hinnant-0510001154380001@ith3-473.twcny.rr.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<karsten.loeffler-7D396D.15575505102000@newsserv.uni-tuebingen.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,6951f08fa8b3ff8d X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,6951f08fa8b3ff8d X-Google-Attributes: gidf635e,public From: hinnant@anti-spam_metrowerks.com (Howard Hinnant) Subject: Re: MP-safe MSL/new() Date: 2000/10/05 Message-ID: <hinnant-0510001154380001@ith3-473.twcny.rr.com> X-Deja-AN: 677920119 References: <karsten.loeffler-7D396D.15575505102000@newsserv.uni-tuebingen.de> X-Complaints-To: abuse@twcny.rr.com X-Trace: typhoon.nyroc.rr.com 970761049 24.24.28.115 (Thu, 05 Oct 2000 11:50:49 EDT) Organization: Metrowerks NNTP-Posting-Date: Thu, 05 Oct 2000 11:50:49 EDT Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac