Boost logo

Boost :

Subject: Re: [boost] [threadpool] new version v12
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-11-03 05:16:32

"Oliver Kowalke" <k-oli_at_[hidden]> writes:

>> > If the fibers are not moved to other worker-threads this shouldn't
>> > be an issue - right?
>> No. The problem is if I am a task running on a worker thread, and I
>> call future::get(), if another task/fiber gets scheduled on my thread
>> then it inherits my locks, thread-local variables and thread ID.
> But this seams to me consistent. Because both fibers run on the same
> thread they should see the same thread ID, the same thread-specific
> storage. Only inheriting locks seams to be odd at the first look -
> but this should also be ok because the locks prevent access of other
> threads. Only if the lock is released twice by the fiber code - nedd
> to think about this issue.

It's OK if the nested task was spawned by this task. If the nested
task was spawned by an unrelated task, then these things become real

Also, if your thread runs an unrelated task the condition it was
waiting for might become ready, but the task is unable to resume
because the new unrelated task is still running. This is why you might
choose to migrate fibers between threads:

1. task A spawns tasks B
2. task B gets picked up by other worker threads
3. task N is submitted to the queue, but there are no free workers
4. task A blocks on task B
5. the thread running task A picks up task N
6. task B completes.
   * task A is now ready to run, but its thread is running task N.
   * Migrate task A to the thread that just completed task B, and
   resume task A (easily done with SwitchToFiber). Everything is fine
   and dandy.... except the thread-local variables and thread ID for
   task A just changed :-(

>> Also, I just remembered that on Windows prior to Vista, SwitchToFiber
>> will not preserve floating-point registers and state. On Vista, you
>> have to specify FIBER_FLAG_FLOAT_SWITCH in the CreateFiberEx call in
>> order to enable this. I don't know how much of a problem that is in
>> practice.
> I didn't read this in the MSDN :( I'll search for it.

See CreateFiberEx and ConvertThreadToFiberEx


Anthony Williams
Author of C++ Concurrency in Action |
Custom Software Development |
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Boost list run by bdawes at, gregod at, cpdaniel at, john at