In multithreaded C/C++, does malloc/new lock the heap when allocating memory

后端 未结 4 677
一整个雨季
一整个雨季 2020-12-24 07:27

I\'m curious as to whether there is a lock on memory allocation if two threads simultaneously request to allocate memory. I am using OpenMP to do multithreading, C++ code.

4条回答
  •  爱一瞬间的悲伤
    2020-12-24 07:52

    http://en.wikipedia.org/wiki/Malloc

    Modern malloc implementations try to be as lock-free as possible by keeping separate "arenas" for each thread.

提交回复
热议问题