> Cute but only a fool would introduce this complexity and overhead for easing their C programming experience.
Anyway, that's cool. Keep up good work, tebrikler :)
> Cute but only a fool would introduce this complexity and overhead for easing their C programming experience.
Anyway, that's cool. Keep up good work, tebrikler :)
So while adding coroutine support to V8 would probably require some substantial internal rewrites, it wouldn't necessitate changing the language - just add a global Coroutine object with the coroutine-switching functions like create, resume, yield...
If you want to look at the Lua coroutine implementation, start at auxresume (http://www.lua.org/source/5.1/lbaselib.c.html#auxresume) in lbaselib.c, and the functions tagged luaB_ more generally. (In 5.2, they've been moved to their own file, lcorolib.c.)
I'm also guessing that it's also not entirely true that there are no shared resource drawbacks. Whenever lthread moves a heavy computation into a pthread, all synchronization bets are presumably off. If you've got two "CPU intensive" workers that reference the same data structures, then you're still going to need mutexes, right?
On average, yielding ~10 calls deep results in copying ~75 to 100 bytes but it all depends on what has been on the stack. One advantage in lthread is it's easy to take advantage of cores which isn't very natural in IO loops.
Yes you'll need a synchronization mechanism when accessing shared data structures from multiple CPU intensive workers.
I often take addresses of local variables -- if I understood correctly, this deserves a huge warning in the documentation.
I thought I added a warning in the lthread_compute_begin() section but apparently not. I'll go ahead and add it.
Additionally, callbacks have the same amount of overhead but it's not constant because you have to create a side-channel for the state management. That means, instead of a simpler stack for keeping the state, you have to have a periodic stack + a structure or object for all the state even when the callback isn't active.
Node.js is the new fad riding on JavaScript wave. I still don't understand what it brings, when comparing it with more sound alternatives.
https://github.com/halayli/lthread/tree/master/src/examples
thanks for the heads up. :)