Boost logo

Boost Users :

From: Martin Pasdzierny (martin_at_[hidden])
Date: 2004-12-11 14:01:30


Peter Dimov wrote:
> Martin Pasdzierny wrote:
>
>> Hello boost::thread experts,
>>
>> does the 'thread_ref-design' as discussed previously enable the
>> following scenario ?
>> <code start>
>>
>> struct thread_class_1 {
>> thread_ref tr;
>> void operator()() {
>> tr = get_current_thread_ref(); // view from *inside* a thread
>> ...
>> }
>> } ;
>> ...
>> thread_class_1 thread_functor_1;
>> boost::thread thread_1(thread_functor_1) ;
>
>
> There are two problems with this code. First, under the thread_ref
> design, there is no boost::thread class:
>
> thread_ref thread1 = create_thread( thread_functor_1 );
>
> Second, create_thread makes a copy of thread_functor_1 and runs the
> copy, as is also the case with the current design.
OK. (In real world I usually do some smart_ptr wrapping around the functors data members)
>
> However, thread1, as returned by create_thread, and the thread_ref
> returned by current_thread inside the newly spawned thread will indeed
> be equivalent. They will not only compare equal, but will be
> interchangeable in every way.
Very good.

Do You plan to change the current implementation ( would be a partial re-implementation) ?

As I posted in another thread:
My personal impression is that an alternative change to the current implementation would
enable at least this extended comparability:

- exposing the (currently internal) thread identifiers (such as thread::m_id thread::m_thread etc.) as
a comparable type thread::id at least as 'protected'.
- thread_group (optionally) gets an additional member like: thread* get_thread(thread:id id);


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net