News for hackers. Stuff that matters.
Re:Simple coroutines for games in C++ by static_noise on Sunday March 20, 2016 @02:41PM (#11324053)
Short version:

The coroutines are regular threads. The library provides an interface for syncing which makes them behave as if they were "real" coroutines. This avoids common problems you run into when making coroutines in C++ which by itself does not support coroutines natively - but it supports threads very well.

Pros: Very easy to implement and use. Will likely work very well anywhere without much thought.

Cons: Resource hungry. Not really designed for thousands of simultaneous coroutines.

Re:Simple coroutines for games in C++ by vvanders on Sunday March 20, 2016 @02:48PM (#11324086)
Yeah, we'd traditionally use coroutines per-actor so this would be way too heavyweight.

It's really nice for scripting things as you can tests a bunch of conditions, yield() and then re-test without needing to build an explicit state machine. Much easier for designers to grok.

Usually done in Lua, which is a fantastic language for gamedev(low overhead, fast, coroutine support and integrates very nicely with C/C++).

Re:Simple coroutines for games in C++ by jasonjei on Sunday March 20, 2016 @03:49PM (#11324339)
Question: couldn't you use OS fibers to do "coroutines" without being resource intensive? I know all major OS kernels have supported fibers for some time...
Re:Simple coroutines for games in C++ by gpderetta on Sunday March 20, 2016 @04:17PM (#11324457)
Linux for one doesn't unless you count the obsolete (and slow) swapcontext.
Re:Simple coroutines for games in C++ by acconsta on Sunday March 20, 2016 @09:40PM (#11325668)
Google implemented fibers. Hopefully they'll get upstreamed.

https://www.youtube.com/watch?v=KXuZi9aeGTw

Re:Simple coroutines for games in C++ by gpderetta on Monday March 21, 2016 @06:34AM (#11327165)
If I remember correctly, that's an additional interface for usermode initiated, cooperative scheduling of kernel threads (basically a variant of pthread_yield that allows specifying which thread is going to get the timeslice we are relinquishing).

It still requites a syscall and the entities being scheduled are proper kernel level threads.

So not really fibers. Pretty cool though.

Edit: autocorrect

Re:Simple coroutines for games in C++ by rumcajz on Monday March 21, 2016 @01:53AM (#11326452)
You can use this: http://libmill.org
Re:Simple coroutines for games in C++ by thechao on Sunday March 20, 2016 @05:00PM (#11324635)
I've recently just started using pthreads with blocking pipes. Not performant, but dead easy to use & reason about.
Re:Simple coroutines for games in C++ by slavik81 on Sunday March 20, 2016 @07:09PM (#11325155)
Whoops. I think I downvoted you by mistake.

By the way, I found barriers to be very simple to work with for some rough multithreading. Just line all the threads up, then let them go.