Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locked thread in spawn #19

Closed
dysinger opened this issue Jul 31, 2012 · 6 comments
Closed

locked thread in spawn #19

dysinger opened this issue Jul 31, 2012 · 6 comments

Comments

@edsko
Copy link
Member

edsko commented Jul 31, 2012

I don't think the issue is that we cannot spawn a closure on master -- when I run your example with just a single node (i.e. the master only), and stick in a threadDelay to make sure the master does not exit before it gets a chance to print the log message, it prints the result of isPrime and then shows the same MVar error that you're showing. I'll investigate.

@dysinger
Copy link
Author

Awesome.

@edsko
Copy link
Member

edsko commented Jul 31, 2012

It's related to spawnLink (as opposed to spawn).

@dysinger
Copy link
Author

Yes I saw it in every variant/extension of spawn too.

@edsko
Copy link
Member

edsko commented Jul 31, 2012

Right, so: the new implementation of Cloud Haskell follows the semantics described in "A Unified Semantics for a Future Erlang". In this semantics, linking makes no distinction between regular termination and abnormal termination. In other words, if you link to a process, and that process dies normally, you die too. This is appropriate for slave processes that link to their masters, where the master should never terminate (masters should monitor their slaves, not link to them). In your example, you are linking to the processes that compute the prime numbers. As soon as this process terminates, the process that spawned it will die too.

The "thread blocked indefinitely" exception you were seeing was a bug, however. The backend starts the master process using "runProcess", which waits for a process to finish -- but it didn't take into account abnormal termination and would beb blocked indefinitely when the process threw an exception. I have fixed this and released it as 0.2.2.0 to Hackage.

If you run your example again (and insert a threadDelay to give the spanwed processes a chance to do anytihng) you will find that the program will now terminate quietly, possibly after or possibly before the log message.

So in summary: you shouldn't use spawnLink here, but you did find a bug. Thanks for the report :)

@edsko edsko closed this as completed Jul 31, 2012
@dysinger
Copy link
Author

Awesome thanks for the update. I was mostly concerned because I didn't see the same behavior in the original 'remote' package (it waits for the spawnLink'ed processes to finish before the main exits) and also the mvar thread lock message.

qnikst added a commit that referenced this issue Oct 19, 2015
Run tests using network-transport-inmemory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants