Discussion:
Fwd: Boost coroutine/context libraries
(too old to reply)
Gregory Laird
2017-01-18 01:20:33 UTC
Permalink
--------------- Forwarded message (begin)

Subject: Boost coroutine/context libraries
From: Gregory Laird <***@northgatebowl.com>
Date: Tue, 17 Jan 2017 17:10:57 -0800
Newsgroup: gmane.comp.lib.boost.user

I am trying to write a cooperative task scheduler in c++ and I have
discovered the boost context and coroutine libraries. I have written these
sorts of schedulers many times in assembly language so I appreciate the
issues in the methodology. I have written lots of c code but am less versed
in c++.

I have been trying to find some straightforward examples of the libraries
use without a lot of extraneous c++ language elements (e.g. binds, lambdas,
etc.). I did find one example

http://stackoverflow.com/questions/11716291/boost-context-class

that is very nice, but it will not compile now with the current boost
library. I get an error saying that boost::context::fcontext_t has been
removed from the public api.

Could someone direct me to some examples that demonstrate the context or
coroutine functionality that would be easier to understand.

I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.

Thanks.
--------------- Forwarded message (end)
Daniel Hofmann
2017-01-18 09:36:48 UTC
Permalink
Post by Gregory Laird
--------------- Forwarded message (begin)
Subject: Boost coroutine/context libraries
Date: Tue, 17 Jan 2017 17:10:57 -0800
Newsgroup: gmane.comp.lib.boost.user
I am trying to write a cooperative task scheduler in c++ and I have
discovered the boost context and coroutine libraries. I have written these
sorts of schedulers many times in assembly language so I appreciate the
issues in the methodology. I have written lots of c code but am less versed
in c++.
I have been trying to find some straightforward examples of the libraries
use without a lot of extraneous c++ language elements (e.g. binds, lambdas,
etc.). I did find one example
http://stackoverflow.com/questions/11716291/boost-context-class
that is very nice, but it will not compile now with the current boost
library. I get an error saying that boost::context::fcontext_t has been
removed from the public api.
Could someone direct me to some examples that demonstrate the context or
coroutine functionality that would be easier to understand.
Maybe this helps - very basic coroutine "scheduler" example:

https://github.com/daniel-j-h/coroutine-scheduler/blob/master/main.cc

I would go with Boost.Coroutine2 / Boost.Coroutine directly instead of
the lower-level context featuers.
Post by Gregory Laird
I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.
Thanks.
--------------- Forwarded message (end)
_______________________________________________
Boost-users mailing list
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Oliver Kowalke
2017-01-18 13:54:20 UTC
Permalink
Post by Gregory Laird
--------------- Forwarded message (begin)
Subject: Boost coroutine/context libraries
Date: Tue, 17 Jan 2017 17:10:57 -0800
Newsgroup: gmane.comp.lib.boost.user
I am trying to write a cooperative task scheduler in c++ and I have
discovered the boost context and coroutine libraries. I have written these
sorts of schedulers many times in assembly language so I appreciate the
issues in the methodology. I have written lots of c code but am less versed
in c++.
I have been trying to find some straightforward examples of the libraries
use without a lot of extraneous c++ language elements (e.g. binds, lambdas,
etc.). I did find one example
http://stackoverflow.com/questions/11716291/boost-context-class
that is very nice, but it will not compile now with the current boost
library. I get an error saying that boost::context::fcontext_t has been
removed from the public api.
Could someone direct me to some examples that demonstrate the context or
coroutine functionality that would be easier to understand.
I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.
- I would use boost.context instead of boost.coroutine(2) for implementing
a scheduler
- boost.context contains an directory ('example') which does contains not
too complicated C++ code
Gregory Laird
2017-01-18 19:38:50 UTC
Permalink
Thank you Oliver for the suggestion. I will have a look. I think you are correct--and this was my feeling as well--that the context functionality is perfect for what I want to do. I just have to get where I understand it.

Question: If I allocate too small of a stack, and something gets written outside of the allocation, is there any way to know that this has occurred?

Thanks,
Greg Laird

----- Original Message -----
From: Oliver Kowalke
To: boost-users
Sent: Wednesday, January 18, 2017 5:54 AM
Subject: Re: [Boost-users] Fwd: Boost coroutine/context libraries


2017-01-18 2:20 GMT+01:00 Gregory Laird <***@northgatebowl.com>:

--------------- Forwarded message (begin)

Subject: Boost coroutine/context libraries
From: Gregory Laird <***@northgatebowl.com>
Date: Tue, 17 Jan 2017 17:10:57 -0800
Newsgroup: gmane.comp.lib.boost.user

I am trying to write a cooperative task scheduler in c++ and I have
discovered the boost context and coroutine libraries. I have written these
sorts of schedulers many times in assembly language so I appreciate the
issues in the methodology. I have written lots of c code but am less versed
in c++.

I have been trying to find some straightforward examples of the libraries
use without a lot of extraneous c++ language elements (e.g. binds, lambdas,
etc.). I did find one example

http://stackoverflow.com/questions/11716291/boost-context-class

that is very nice, but it will not compile now with the current boost
library. I get an error saying that boost::context::fcontext_t has been
removed from the public api.

Could someone direct me to some examples that demonstrate the context or
coroutine functionality that would be easier to understand.

I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.



- I would use boost.context instead of boost.coroutine(2) for implementing a scheduler

- boost.context contains an directory ('example') which does contains not too complicated C++ code
Daniel Anderson
2017-01-18 22:51:27 UTC
Permalink
Yes, you can use markers around your stack, and you verify them once you
get control back, or at the end when the coroutine terminate

often debug version of new/delete will provide this facility which can be
leverage when allocation your stack.

but if a coroutine has written outside the stack, it could have corrupted
the program memory enough that you will not be able to recover and report
the error.

there might be something in low level of your C++ runtime which you can
hook to know when a function is called and how much stack it needs. if this
facility exist then you can leverage it to prevent you coroutines from
overflowing the stack. It used to be possible with Microsoft C++, I do not
know with gcc or clang.
Post by Gregory Laird
Thank you Oliver for the suggestion. I will have a look. I think you are
correct--and this was my feeling as well--that the context functionality is
perfect for what I want to do. I just have to get where I understand it.
Question: If I allocate too small of a stack, and something gets written
outside of the allocation, is there any way to know that this has occurred?
Thanks,
Greg Laird
----- Original Message -----
*Sent:* Wednesday, January 18, 2017 5:54 AM
*Subject:* Re: [Boost-users] Fwd: Boost coroutine/context libraries
Post by Gregory Laird
--------------- Forwarded message (begin)
Subject: Boost coroutine/context libraries
Date: Tue, 17 Jan 2017 17:10:57 -0800
Newsgroup: gmane.comp.lib.boost.user
I am trying to write a cooperative task scheduler in c++ and I have
discovered the boost context and coroutine libraries. I have written these
sorts of schedulers many times in assembly language so I appreciate the
issues in the methodology. I have written lots of c code but am less versed
in c++.
I have been trying to find some straightforward examples of the libraries
use without a lot of extraneous c++ language elements (e.g. binds, lambdas,
etc.). I did find one example
http://stackoverflow.com/questions/11716291/boost-context-class
that is very nice, but it will not compile now with the current boost
library. I get an error saying that boost::context::fcontext_t has been
removed from the public api.
Could someone direct me to some examples that demonstrate the context or
coroutine functionality that would be easier to understand.
I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.
- I would use boost.context instead of boost.coroutine(2) for implementing a scheduler
- boost.context contains an directory ('example') which does contains not
too complicated C++ code
------------------------------
_______________________________________________
Boost-users mailing list
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
Daniel
*L'action accÚde à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
Nat Goodspeed
2017-01-19 04:00:39 UTC
Permalink
On Jan 18, 2017 2:39 PM, "Gregory Laird" <***@northgatebowl.com> wrote:

Question: If I allocate too small of a stack, and something gets written
outside of the allocation, is there any way to know that this has occurred?


http://www.boost.org/doc/libs/1_63_0/libs/context/doc/html/context/stack/protected_fixedsize.html
Oliver Kowalke
2017-01-20 07:47:24 UTC
Permalink
Post by Gregory Laird
Question: If I allocate too small of a stack, and something gets written
outside of the allocation, is there any way to know that this has occurred?
In the best case you get a segmentation fault (in worst case you get
undefined behaviour).

You could use the protected_fixedsize_stack allocator - it appends a guard
page at the end of the stack (only virtual addresses, no physical memory is
wasted). If you try to access memory from the guard page you get a
segmentation fault.
Another possibility is to use the segmented_stack allocator. It extends the
stack on demand (supported by gcc-4.7 onwards) - but you are forced to use
execution_context v1.

Gavin Lambert
2017-01-19 00:54:09 UTC
Permalink
Post by Gregory Laird
I want to write a scheduler that is very similar to the example listed above
where coroutines yeild back to a main caller which then chooses the next
coroutine to continue its processing.
- I would use boost.context instead of boost.coroutine(2) for
implementing a scheduler
- boost.context contains an directory ('example') which does contains
not too complicated C++ code
Boost.Fiber might also be worthwhile to look at, depending on your
needs. It was added fairly recently though so you might need a newer Boost.
Loading...