2

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

4

2 回答 2

4

那么这个源Intel Threading Building Blocks听起来更直接(参见“TBB Scalable Allocator”页面)-

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

– 大小隔离的 bin 提高了局部性
– 私有堆减少了同步开销和错误共享

更新:从这里-

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.

但是错误共享是关于减速而不是线程安全。

于 2013-04-10T19:09:52.243 回答
2

根据您链接的手册:

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

两个线程可以在不同的对象上同时调用方法或函数,但不能在同一个对象上调用。两个线程在同一个对象上同时调用方法或函数是不安全的。类的描述与此约定不同。例如,并发容器更自由。从本质上讲,它们确实允许对同一个容器对象进行一些并发操作。

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

于 2013-04-10T18:58:13.707 回答