c++ constructor in atomic section

c++ constructor in atomic section

I have a problem with intel stm compiler and i hope you can help me. So,
i have an application which is implemented with c++ and then i used
intel stm compiler to build atomic section (__tm_atomic {...}) there are
many c++ constructor in the atomic section (a = new b();) When i got
runtime statistics with stm compiler, according to the number of
serialTransaction number, i saw that those constructors inside critical
sections run in serial. But i want them to run in parallel. How can i
solve this problem? Does stm compiler support c++ constructor in the
atomic section?

ps. I defined constructor functions as a __attribute__((tm_callable)).
Is it right?

Thank you very much in advance

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Gokcen, we support marking for C++ c'tors for transactiona execution anddefining them as __attribute__((tm_callable)) is absolutely correct way to achieve your goal. However, there are couple of problems associated with c'tors in STM 2.0 Compiler those already fixed and will be addressed in the next release:

- As far as I remember there is no way to mark implicit c'tors/d'tors as tm_callable in STM Compiler 2.0;

- Support for new/delete inatomic sectionis far from ideal in this version of compiler -this may be your case according to information given.

If it is possible to see the sample of code like yours (with class and its c'tor definition and sample of atomic section), please post it here to let me understand what's happenning and give you more precise answer.

And minor hint:allocating memory inside tranaction is not a very good practice sincememory may be actually allocated and deallocated many times because of contentions and retries (causing memory thrashing and excessive burden on memory allocator) andmemory allocation itself is synchronized anywaysso you might want to cosider pulling memory allocation out of atomic block (of course this is not alwayspossible, so this is just a hint).


Just to clarify one of Serge's points.

The compiler and run time do correctly transactionalize the use of C memory allocation routines (malloc, calloc, free, realloc) inside transactions, so there is no need to do anything special to handle those, and they will not cause serialization. However the What-If 2 system does not specifically handle new/delete (new[]/delete[]), so use of those in transactions may well serialize the transaction.

Of course this is not ideal, and we'd like to fix it in a future release.

-- Jim

You should override new (and probably also delete) operators for the classes you are instantiating inside transactions. Alternatively you can override the global new/delete operators.

This should work:


void* operator new (size_t size)


return malloc(size);



void operator delete (void *ptr)




Hope this helps,


Leave a Comment

Please sign in to add a comment. Not a member? Join today