![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
boost
文章平均质量分 75
nodeathphoenix
这个作者很懒,什么都没留下…
展开
-
boost thread 使用类的非静态成员函数做线程函数之【原理】
大家知道,pthread_create()函数的线程函数必须是静态的函数,以标准的__cdecl的方式调用的,而C++的成员函数是以__thiscall的方式调用的,相当于一个普通函数有一个默认的const ClassType* this参数。 为数据封装的需要,我常常把线程函数封装在一个类的内部,定义一个类的私有静态成员函数来作为pthread的线程函数,通常如下: class转载 2011-10-17 14:12:16 · 3263 阅读 · 0 评论 -
C++ boost库----share_from_this类的作用和实现原理
使用boost库时,经常会看到如下的类 class A:public enable_share_from_this 在什么情况下要使类A继承enable_share_from_this? 使用场合:当类A被share_ptr管理,且在类A的成员函数里需要把当前类对象作为参数传给其他函数时,就需要传递一个指向自身的share_ptr。 我们就使类A继承enable_share_from_th转载 2016-10-13 14:41:07 · 590 阅读 · 0 评论 -
shared_ptr构造函数
http://www.cplusplus.com/reference/memory/shared_ptr/shared_ptr/ default (1) constexpr shared_ptr() noexcept; from null pointer (2) constexpr shared_ptr(nullptr_t) : shared_ptr() {} from pointer (3原创 2017-01-17 20:24:41 · 6365 阅读 · 0 评论 -
enable_from_this方法的使用与陷阱
enable_from_this 的使用与实现原理说明: shared_from_this()是enable_shared_from_this的成员函数,返回shared_ptr; 注意的是,这个函数仅在shared_ptr的构造函数被调用之后才能使用。 原因是enable_shared_from_this::weak_ptr并不在构造函数中设置,而是在shared_ptr的构造函数转载 2016-10-13 14:44:39 · 3404 阅读 · 1 评论 -
boost thread usage
1 Condition notify()和notifyAll()都是Object对象用于通知处在等待该对象的线程的方法。两者的最大区别在于: notifyAll使所有原来在该对象上等待被notify的线程统统试图去退出wait的状态,即都去竞争等待该对象上的锁。如果其中的某一个竞争中获胜,得到了condition对象上的锁,它就会马上lock住该锁,并且退出wait函数;其它竞争中失败的wai原创 2011-10-31 10:25:33 · 826 阅读 · 0 评论