Arc Forumnew | comments | leaders | submitlogin
2 points by aw 5459 days ago | link | parent

Not sure if MzScheme's kill-thread is guaranteed to kill a thread "instantly"? If not, then you have a race condition: you schedule a thread to be killed, but it maybe has just enough time to enter an atomic block before it dies.

But you're on the right track though. We actually don't want to kill a thread in the middle of an atomic... in your very first example, (thread:atomic (while t)), it would be a bug if kill-thread did break that loop. The whole point of "atomic" is that the operation completes before other threads see the result.

So the desired behavior is if a thread is "killed" in the middle of an atomic block, it should finish the block (and release the lock in the normal way), and then die.

The MzScheme documentation web site is down at the moment so I can't look now, but if I recall there is some kind of break or signal mechanism in MzScheme that might help.



1 point by elibarzilay 5459 days ago | link

The documentation server is back up.

-----

1 point by akkartik 5459 days ago | link

Still down for me, but from google's cache:

"Terminates the specified thread immediately, or suspends the thread if thd was created with thread/suspend-to-kill." http://74.125.155.132/search?q=cache:kdhjq2ukTtgJ:download.p...

So it seems kill-thread is guaranteed to kill the thread by the time it returns.

-----

1 point by akkartik 5458 days ago | link

Oh, but break-thread is not: "Registers a break with the specified thread." http://docs.plt-scheme.org/reference/threads.html#%28def._%2... "When a break is detected and enabled, the exn:break exception is raised in the thread sometime afterward" http://docs.plt-scheme.org/reference/breakhandler.html

-----