Subject: Re: [boost] [threadpool] new version v12
From: Oliver Kowalke (k-oli_at_[hidden])
Date: 2008-11-03 05:36:22
> 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
Sorry I don't know the semantic of an 'urelated task'. Do you mean a task created by another worker-thread?
> 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 :-(
I got it. This happens if migration of fibered tasks between worker-threads happens.
But what about executing fibered tasks only in the worker-thread which has created the fiber?
In Boost.Threadpool a new fiber is created for each task which has been dequeued from the global queue, the local worker-queue or stolen from the worker-queue of another worker-thread.
If the fibered task has yield its execution it is stored into a list in the thread-specific storage (list of unfinished fibers).
In the worker-thread loop first all fibers of the unfinished list will be executed. If a fiber becomes finished it is removed from the list in the other case it is sored again in this list. The iteration continues until the size of this list doesn't change.
Then a new task is dequeued from the local worker-queue, then from the global -queue and then from worker-queues of other threads.
> See CreateFiberEx and ConvertThreadToFiberEx
-- "Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk