如何在C ++中实现线程安全引用计数 [英] How to implement thread safe reference counting in C++

查看:374
本文介绍了如何在C ++中实现线程安全引用计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C ++编程语言在X86 CPU上实现高效且线程安全的引用计数系统?

How do you implement an efficient and thread safe reference counting system on X86 CPUs in the C++ programming language?

我总是遇到关键操作不是原子操作的问题,并且可用的X86 Interlock操作不足以实现引用计数系统.

I always run into the problem that the critical operations not atomic, and the available X86 Interlock operations are not sufficient for implementing the ref counting system.

以下文章涵盖了该主题,但需要特殊的CPU指令:

The following article covers this topic, but requires special CPU instructions:

http://www.ddj.com/architect/184401888

推荐答案

现在,您可以使用Boost/TR1 shared_ptr<>智能指针来保持引用计数.

Nowadays, you can use the Boost/TR1 shared_ptr<> smart pointer to keep your reference counted references.

效果很好;没有大惊小怪,没有糊涂. shared_ptr<>类负责处理对引用计数的所有锁定.

Works great; no fuss, no muss. The shared_ptr<> class takes care of all the locking needed on the refcount.

这篇关于如何在C ++中实现线程安全引用计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆