
Is is possible to inherit from boost::thread and then store pointers to instantiated objects of such classes in say ptr_vector<>? I need to interrupt() a specific thread now and then and once you commit a thread to thread_group you can only interrupt them all at once.

Zitat von anony
Is is possible to inherit from boost::thread and then store pointers to instantiated objects of such classes in say ptr_vector<>?
why inherit? you can store boost::thread's (or classes that contain a boost::thread) in a ptr_vector.
I need to interrupt() a specific thread now and then and once you commit a thread to thread_group you can only interrupt them all at once.
I don't understand why there even is a class thread_group. it seems to me it was only intended to work around the fact that thread's are non-Assignable, which is much better solved by MoveAssignable in the future, and pointer containers or swap()ing in the meantime.

On 03/13/10 19:58, strasser@uni-bremen.de wrote:
Zitat von anony
: Is is possible to inherit from boost::thread and then store pointers to instantiated objects of such classes in say ptr_vector<>?
why inherit? you can store boost::thread's (or classes that contain a boost::thread) in a ptr_vector.
Yes I can, but I need the object pointers too, not just thread pointers.
I need to interrupt() a specific thread now and then and once you commit a thread to thread_group you can only interrupt them all at once. I don't understand why there even is a class thread_group. it seems to me it was only intended to work around the fact that thread's are non-Assignable, which is much better solved by MoveAssignable in the future, and pointer containers or swap()ing in the meantime.
Well, someone is bound to be using it. Anyway, I've tested the idiom and it works, maybe someone can reveal a bad side to it if there is one.

Zitat von anony
On 03/13/10 19:58, strasser@uni-bremen.de wrote:
Zitat von anony
: Is is possible to inherit from boost::thread and then store pointers to instantiated objects of such classes in say ptr_vector<>?
why inherit? you can store boost::thread's (or classes that contain a boost::thread) in a ptr_vector.
Yes I can, but I need the object pointers too, not just thread pointers.
struct A{ public: A(){ // (1) boost::thread(bind(&A::start,this)).swap(this->thr); } void start(){ ... } private: boost::thread thr; }; ptr_vector<A> avec; (1) you could also construct A::thr upfront, but some compilers generate warnings if the "this"-pointer is used in member initializers

struct A{ public: A(){ // (1) boost::thread(bind(&A::start,this)).swap(this->thr); } void start(){ ... } private: boost::thread thr; };
ptr_vector<A> avec;
(1) you could also construct A::thr upfront, but some compilers generate warnings if the "this"-pointer is used in member initializers
But I am not going to be able to call, say, avec.front().interrupt(), or avec.front().join() from outside the class this way. Another thing, how about doing just: thr = boost::thread(bind(&A::start, this)); I think you had to swap in earlier versions of the library. Is assignment more efficient than swap in the newer ones? If I have boost::thread as one of the bases no swaps or assignments are needed btw...
participants (2)
-
anony
-
strasser@uni-bremen.de