How should I use new in a multithread environment?
Precisely: I have a piece of code that I run with 40 threads. Each thread invokes new a few times. I noticed that performance drops, probably because threads lock in new (significant time is spent in __lll_lock_wait_parallel and __lll_unlock_wait_parallel). What is the best alternative to new / delete I can use?
Related:
http://dsc.sun.com/solaris/articles/multiproc/multiproc.html
Is malloc thread-safe?
Even if you are using the new operator, its using malloc underneath to do the allocation and deallocation. The focus should be on the allocator and not the API used to reach it in these circumstances.
TCMalloc is a malloc created at Google specifically for good performance in a multi-threading environment. It is part of google-perf-tools.
Another malloc you might look at is Hoard. It has much the same aims as TCMalloc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With