
Has anyone considered developing/submitting a coroutine library for boost? I've been developing C/C++ for years, and only just discovered how incredibly useful userspace single-threaded multitasking is, if you want to avoid the huge overhead of POSIX threads, and don't mind having to explicitly yield to other threads in your code (indeed, this makes the issues of concurrency and synchronization between threads just much simpler). I've written a wrapper around PCL (http://www.xmailserver.org/libpcl.html) and have since found it to be at least as useful as many of the other boost libraries in my last few projects, in particular in a select-driven single-thread socket server which i am working on now.

Hi, Check the Boost Vault, under concurrent programming folder for the continuations library http://www.boost-consulting.com/vault/ I think the author, G. Deretta, plans to develop it further and adapt it to final boost::asio and submit it Search the Boost mailing list for more info (the lib is UNIX-only right now). On 4/23/06, Victor Condino <un1tz3r0@gmail.com> wrote:
Has anyone considered developing/submitting a coroutine library for boost? I've been developing C/C++ for years, and only just discovered how incredibly useful userspace single-threaded multitasking is, if you want to avoid the huge overhead of POSIX threads, and don't mind having to explicitly yield to other threads in your code (indeed, this makes the issues of concurrency and synchronization between threads just much simpler).
I've written a wrapper around PCL (http://www.xmailserver.org/libpcl.html) and have since found it to be at least as useful as many of the other boost libraries in my last few projects, in particular in a select-driven single-thread socket server which i am working on now. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 4/23/06, Jose <jmalv04@gmail.com> wrote:
Hi,
Check the Boost Vault, under concurrent programming folder for the continuations library http://www.boost-consulting.com/vault/
I think the author, G. Deretta, plans to develop it further and adapt it to final boost::asio and submit it Search the Boost mailing list for more info (the lib is UNIX-only right now).
Hello all, Yes, the library is unix only currently (porting it to windows using fibers should be semitrivial, but i do not currently have a windows development box ). The version in the vault does not compile currently (broken makefiles if i recall correctly). Unfortunately i do not have a reliable internet connection currently and i will not be able to upload an updated version until at least tomorrow. Development is going on, albeit slowly. I'm waiting for boost::asio to finalize its interface before continuing. The library is pretty small, so it is not that much work. ------ Giovanni P. Deretta

Do you plan make it work correctly with C++ exception handling? I've tried Gnu Pth ~ 6 month ago and user context switch caused mess in exception handlers. Alexey On 4/24/06, Giovanni Piero Deretta <gpderetta@gmail.com> wrote:
On 4/23/06, Jose <jmalv04@gmail.com> wrote:
Hi,
Check the Boost Vault, under concurrent programming folder for the continuations library http://www.boost-consulting.com/vault/
I think the author, G. Deretta, plans to develop it further and adapt it to final boost::asio and submit it Search the Boost mailing list for more info (the lib is UNIX-only right now).
Hello all,
Yes, the library is unix only currently (porting it to windows using fibers should be semitrivial, but i do not currently have a windows development box ). The version in the vault does not compile currently (broken makefiles if i recall correctly). Unfortunately i do not have a reliable internet connection currently and i will not be able to upload an updated version until at least tomorrow.
Development is going on, albeit slowly. I'm waiting for boost::asio to finalize its interface before continuing. The library is pretty small, so it is not that much work.
------ Giovanni P. Deretta _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Alexey Trenikhin wrote:
Do you plan make it work correctly with C++ exception handling? I've tried Gnu Pth ~ 6 month ago and user context switch caused mess in exception handlers.
Alexey What do you exactly means with correctly? What are the problems are you seeing with Pth? On witch platform?
Ideally exception handling should work int the same way as with kernel (native) threads. If that can't be done, coroutines aren't going be that useful. -- Giovanni P. Deretta

When pth switched user context it did not switch exception handlers. For example Coroutine A: try{ switch_to_B(); throw 1; } catch(int){ printf("catched in A") } Coroutine B: try{ switch_to_A(); printf("bbb"); } catch(int){ printf("catched in B") } main: create_A(); create_B(); switch_toA(); result: catched in B It was on gcc 3.4.4 under cygwin and linux@nslu2 On 4/25/06, Giovanni P. Deretta <gpderetta@gmail.com> wrote:
Do you plan make it work correctly with C++ exception handling? I've
Alexey Trenikhin wrote: tried
Gnu Pth ~ 6 month ago and user context switch caused mess in exception handlers.
Alexey What do you exactly means with correctly? What are the problems are you seeing with Pth? On witch platform?
Ideally exception handling should work int the same way as with kernel (native) threads. If that can't be done, coroutines aren't going be that useful.
-- Giovanni P. Deretta _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Alexey Trenikhin wrote:
When pth switched user context it did not switch exception handlers. For example Coroutine A: try{ switch_to_B(); throw 1; } catch(int){ printf("catched in A") }
Coroutine B: try{ switch_to_A(); printf("bbb"); } catch(int){ printf("catched in B") }
main: create_A(); create_B(); switch_toA();
result: catched in B
I've ran almost the same test using my library and it seems to do the right thing. I can't try Pth right now, but i suspect it would work too, as both libraries are similar. I'm running gcc 3.3.6 under slackware-current. As gcc exception model has not changed since 3.0 (or so), i think that the problem is the platform: I'm not sure, but i think that gcc on windows uses a different system to handle exceptions, putting exception handler data on the stack (to be compatible with other win compilers and the OS itself), while on linux, and maybe other OSes, it uses a different method that need no stack data and only relies on the instruction pointer and registers value (the zero overhead exception model). I might be wrong, but i cannot think of anything else. I'll investigate more later. -- Giovanni P. Deretta

On 4/28/06, Giovanni P. Deretta <gpderetta@gmail.com> wrote:
I've ran almost the same test using my library and it seems to do the right thing. I can't try Pth right now, but i suspect it would work too, as both libraries are similar. I'm running gcc 3.3.6 under slackware-current. As gcc exception model has not changed since 3.0 (or so), i think that the problem is the platform: I'm not sure, but i think that gcc on windows uses a different system to handle exceptions, putting exception handler data on the stack (to be compatible with other win compilers and the OS itself), while on linux, and maybe other OSes, it uses a different method that need no stack data and only relies on the instruction pointer and registers value (the zero overhead exception model).
I might be wrong, but i cannot think of anything else.
I beleive you are right about platform. But I think problem not in using stack (stack is switched anyway), but more likely context switching mechanism does not switch FS:[0] which points to top exception registration record. Btw, I can participate in porting/testing windows/fibers version (if it is not early than May 25th)

Alexey Trenikhin wrote:
On 4/28/06, Giovanni P. Deretta <gpderetta@gmail.com> wrote:
I've ran almost the same test using my library and it seems to do the right thing. I can't try Pth right now, but i suspect it would work too, as both libraries are similar. I'm running gcc 3.3.6 under slackware-current. As gcc exception model has not changed since 3.0 (or so), i think that the problem is the platform: I'm not sure, but i think that gcc on windows uses a different system to handle exceptions, putting exception handler data on the stack (to be compatible with other win compilers and the OS itself), while on linux, and maybe other OSes, it uses a different method that need no stack data and only relies on the instruction pointer and registers value (the zero overhead exception model).
I might be wrong, but i cannot think of anything else.
I beleive you are right about platform. But I think problem not in using stack (stack is switched anyway), but more likely context switching mechanism does not switch FS:[0] which points to top exception registration record.
I've done some little research (googled for 'windows exceptions and fibers') and have obtained conflicting results. Some sources claim that fibers are not completely safe in the face of exceptions, other (most of them) claim that fibers correctly handle them. Anyway, i downloaded and looked at Pth code, and it does not uses fibers on windows (it manually modifies the stack pointer in the setjmp jmp_buf). Let's hope that using fibers will do The Righ Thing (TM).
Btw, I can participate in porting/testing windows/fibers version (if it is not early than May 25th)
Help for Windows porting would be greatly appreciated. I plan to submit the library for the google SoC, so the time frame for the completion is not short (whole summer). -- Giovanni P. Deretta

Wonderful... this is actually exactly what I was looking for... :) i've been using a very very hacked together version of this, without the benefit of the asio library, which from what i've seen looks like the perfect framework for the i/o side of such code. i'm looking forward to following the development. thanks for the help - V. M. Condino On 4/24/06, Giovanni Piero Deretta <gpderetta@gmail.com> wrote:
On 4/23/06, Jose <jmalv04@gmail.com> wrote:
Check the Boost Vault, under concurrent programming folder for the continuations library http://www.boost-consulting.com/vault/
I think the author, G. Deretta, plans to develop it further and adapt it to final boost::asio and submit it Search the Boost mailing list for more info (the lib is UNIX-only right now).
Development is going on, albeit slowly. I'm waiting for boost::asio to finalize its interface before continuing. The library is pretty small, so it is not that much work.
participants (5)
-
Alexey Trenikhin
-
Giovanni P. Deretta
-
Giovanni Piero Deretta
-
Jose
-
Victor Condino