Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: new operator not thread safe?

Author: David Rasmussen

Date: 04:56:10 10/08/02

Go up one level in this thread


On October 08, 2002 at 01:00:31, James Robertson wrote:

>I am writing a C++ program for one of my classes and the professor informed us
>that we must use malloc/free instead of new/delete as new/delete are not thread
>safe. The program is using POSIX threads. Can anyone confirm or deny that new
>and delete are in fact no-nos in multithreading?
>
>James

The C++ standard doesn't mention threading at all, since it is not part of C++.
Many implementations do have a threadsafe implementation of new and delete and
the Standard C++ Library etc. In many implementations you can choose which
library to choose. In MSVC++ there are four libraries: Debug and release
versions of threaded and non-threaded libraries. So it depends on the compiler
you use. If you want to be portable, you have to assume that things are not
threadsafe, as this is not required by any standard. malloc() and free() aren't
guaranteed to be thread-safe either.
In practice, it shouldn't be too hard to find a threadsafe implemenation.

/David



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.