
Oliver Kowalke <k-oli@gmx.de> writes:
Am 28.07.2010 19:21, schrieb Hartmut Kaiser:
The TIB is not changed (only the pointers pointing to the limit and base of the stack).
That will result in problems, I'm sure - at least as soon as you start moving context's between threads. Could you describe a scenario which will trigger an error, please?
Anything that uses thread-local variables or fiber-local variables will fail if you just run it on another thread or fiber. This can include C runtime functions --- errno is typically thread-local, for example.
AFAIK migrating Win32 Fibers between threads is not possible and cloning also not - but maybe I'm wrong in this point.
Moving Windows fibers between threads is definitely possible.
Or do I have to use a special function form the Win32 API?
You need 3 fibers to move a fiber between threads: Thread A is running Fiber 1. It switches to Fiber 2. Thread B is running Fiber 3. It switches to Fiber 1. Hey presto, fiber 1 has switched threads. All is now well, provided code on Fiber 1 doesn't use thread-local variables. Recent versions of the MSVC runtime use fiber-local variables instead of thread-local ones, so standard C and C++ functions should be OK, but e.g. boost::thread uses thread-local variables for things like the thread ID, thread_specific_ptr variables and at_thread_exit handlers. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976