线程安全的TBB可扩展分配器

Thread-safe TBB scalable allocator

本文关键字:可扩展 分配器 TBB 安全 线程      更新时间:2023-10-16

最近我从系统内存管理(malloc/free)切换到英特尔的TBB可扩展分配器。问题是我找不到任何信息,如果它是线程安全的。整个TBB是围绕线程构建的,所以它看起来是合乎逻辑的,但没有具体的证据,我不想假设这样的事情。但是,我也不想进行任何不必要的同步。有人知道这方面的信息吗?

那么这个源代码英特尔线程构建块听起来更直接(参见"TBB可伸缩分配器"页)-

每个线程都有自己的私有堆

-尺寸隔离箱改善局部性
私有堆减少同步开销和错误共享

Update: And from here-

TBB为每个线程池提供了一个可伸缩的分配器。它可能仍然存在虚假分享。

   example: false sharing could matter in pipelining.
   TBB also provides a cache-aligned allocator, which guarantees
   that any two things you've allocated will never experience
   false sharing. The downside is that it has larger memory
   pressure. This is accomplished by making the minimum allocation
   N cache lines, where N is a small integer.
   In the book, the conventional wisdom is to start with the
   scalable allocator and see if switching to the cache-aligned
   allocator speeds things up.

根据您所链接的手册:

除非另有说明,库的线程安全规则为如下:

两个线程可以并发地调用一个方法或函数对象,但不是同一个对象。两个线程同时使用是不安全的在同一对象上并发调用方法或函数。类的描述说明了与此惯例的背离。为例如,并发容器更自由。就其本质而言,它们确实允许在同一容器上进行一些并发操作对象。

对于可伸缩分配器,这意味着两个线程不能同时释放相同的内存,这应该不足为奇。