C++无锁模板化对象池
它们存在吗?
*添加澄清:
是否有任何可用的库实现无锁(这是线程安全的,可能实现自旋锁或其他轻量级同步)ObjectPool(http://en.wikipedia.org/wiki/Object_pool_pattern ) 使用模板用 C++ 语言编写?
do they exist ?
*added to clarify:
is there any usable library that implement lock-free (which is threadsafe and might be implement spinlock or other lightweight synchronization) ObjectPool ( http://en.wikipedia.org/wiki/Object_pool_pattern ) written in C++ language using template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终编写了自己的对象池,它是线程安全的、无锁的、多核可扩展的,经过基准测试:
它可以使用 4 个线程在 Intel Core 2 Quad 2.4 GHz win7-x64 上每秒执行 1660 万次借用-返回操作
`
`
I ended up writing my own object pool, its thread-safe, lock-free and multi-core scalable, benchmarked:
it could do 16.6 Million borrow-return operations per second on Intel Core 2 Quad 2.4 GHz win7-x64 using 4 threads
`
`
你最好的选择是查看 Boost.Pool< /a>,并为其编写一个无锁分配器/互斥接口。
Your best bet would be to check out Boost.Pool, and write a lock free allocator/mutex interface for it.
鉴于存在无锁队列,我想说,如果池不存在,您当然可以创建一个(几乎)无锁池。
结合经典的 tmalloc 分配器(可能会锁定但尽可能避免它),我认为您将接近您的目标。
Given that there are lock-free queues, I would say that if the pool does not exist, surely you can create one (almost) lock-free pool.
Combined with the classic tmalloc allocator (which may lock but avoids it as much as possible), I think you would be nearing your goal.