Sign in to follow this  
Decept

Is new thread safe?

Recommended Posts

Yes.
Things to note:
The standard has no concept of threads. Thus any threaded code is inheritly NOT thread safe due to the fact that compilers are allowed to reorder operations, sometimes that reordering "could" result in code that is not thread safe. However, compilers typically have threading intrinsics that they recognize and hence will avoid reorderings in relation to those intrinsics. Neverless, due to the complete lack of awareness about threads, the standard does not provide that new, delete, or any operation be "safe" for threading. However, in your case (Visual Studio 2005), new uses HeapAlloc without the HEAP_NO_SERIALIZE flag, and hence is thread safe.

Share this post


Link to post
Share on other sites
thanks for answering (man you guys are quick). Sorry it took me so long to get back to you.

That's good news that about new in VS2005. I have a follow up question regarding thread safety. I'm creating some code that uses winsock and I use the functions send() and recv(). Currently I use send() on the main thread and recv() in a separate thread. Is there any danger if those two functions run at the same time?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this