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

后端 未结 4 672
一整个雨季
一整个雨季 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:43

    There could be improvements in certain implementations, such as creating a thread-specific cache (in this case allocations of small blocks will be lock-free). For instance, this from Google. But in general, yes, there is a lock on memory allocations.

提交回复
热议问题