RE: Pre-emptive or co-operative concurrency (was: Concurrency)

On 29 March 2006 17:34, Neil Mitchell wrote:
context-switches happen only on specific events, which every thread will usually engage in, although it need not always do so:
1 only calls to yield 2 any calls to concurrency library api 3 any allocation
The Yhc concurrency switches every n instructions, and therefore even an "evil" thread cannot lock up the system.
Of course, even with fully pre-emptive scheduling, you've still got deadlocks...
Neil, What does YHC do about in-progress thunk evaluations when a context switch happens? Does it use blackholing like GHC, or does it portentially duplicate the work, or something else? Cheers, Simon

Hi
What does YHC do about in-progress thunk evaluations when a context switch happens? Does it use blackholing like GHC, or does it portentially duplicate the work, or something else?
As far as I am aware, since it only switches on instruction boundaries, it never has to worry about this. It certainly doesn't duplicate work, and I think the blackholing is just used for circular dependancy problems, exactly as before threading became used. To be honest, for concurrency I'm a bit out of my depth, Tom did all the design and implementation. Thanks Neil

What does YHC do about in-progress thunk evaluations when a context switch happens? Does it use blackholing like GHC, or does it portentially duplicate the work, or something else?
As far as I am aware, since it only switches on instruction boundaries, it never has to worry about this.
Not quite true. If the same shared expression occurs in two different threads, the first thread to come across it may start evaluating it, then be suspended before completing. If the second thread then comes along and tries to evaluate the expression, what should it do? There are two choices: * Restart evaluating the expression from the beginning. (Duplicates the work, updates the same closure twice. Let's hope closure-update is atomic, or there could be race conditions.) * Back off and let the original thread complete the work. (Implies blackhole detection, plus a queue of threads blocked on blackholes rather than on MVars.) Regards, Malcolm
participants (3)
-
Malcolm Wallace
-
Neil Mitchell
-
Simon Marlow