Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^5: [OT]: threading recursive subroutines.

by Corion (Pope)
on Feb 03, 2011 at 11:43 UTC ( #885974=note: print w/replies, xml ) Need Help??

in reply to Re^4: [OT]: threading recursive subroutines.
in thread [OT]: threading recursive subroutines.

I think that this trampoline approach makes sense and would well mesh with asynchronous IO and "green" (userspace) threads as Coro implements them:

Once your central code dispatcher (GCD) runs out of idle CPU cores/worker threads, it doesn't dispatch function calls by launching a new native thread but suspends the currently executing context and switches to another context using the method that Coro employs, switching out the (relevant part of the) C stack for another. This would basically be transparent to the main code, except for the drawback that parallel execution means more race conditions. When using Coro alone, you don't get nasty race conditions, because there is no parallel execution of Perl code. But you're not worse off than with plain threads.

The small problem that remains is that threads and Coro are unlikely to mix well. Coro itself claims that it is not iThread-safe, and I have little doubt that this is a false claim. and I have no reason to believe otherwise. I presume one of the more interesting problems will be how to move one coroutine context (basically a copy of the C or Perl call stack) across thread stack boundaries without messing up too many things. But maybe reusing the ideas (and clever macros, and development research) of Coro gives enough foothold to implement transparent switching between green and native threads.

Update: Clarified sentence about my impression how badly Coro and threads interact.

  • Comment on Re^5: [OT]: threading recursive subroutines.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885974]
[shmem]: karlgoethebier: isn't bike riding a way of fixing lumbago?
[karlgoethebier]: shmem: scheiss technik
[karlgoethebier]: shmem: yes - i f you manage it to get on the bike. and pray if you must stop...
[shmem]: in the french alpes, at the end of a gravel road, we had a beer at a hut - and heard an enduro coming up.
[shmem]: not by the road, but from there below where you wouldn't want to walk.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-06-25 20:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (570 votes). Check out past polls.