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

Haxe-based threads have no API for stopping them #5800

Closed
jgranick opened this issue Nov 7, 2016 · 7 comments
Closed

Haxe-based threads have no API for stopping them #5800

jgranick opened this issue Nov 7, 2016 · 7 comments

Comments

@jgranick
Copy link

jgranick commented Nov 7, 2016

Once Haxe-based code relies more upon multiple threads, the need for being able to kill or stop a thread becomes more important.

For example (in pseudo-code):

var backgroundURLRequest = request ("site.png");

Timer.delay (function () {
    if (backgroundURLRequest.loaded) {
        backgroundURLRequest.cancel ();
    }
}, 30000);

Is there any way to safely interrupt a Haxe created thread?

@Simn
Copy link
Member

Simn commented Nov 9, 2016

I was under the impression that you can just Sys.exit out of your threads...

@ibilon
Copy link
Member

ibilon commented Nov 9, 2016

I think @jgranick means from outside of the thread,
for instance if you launched a background calculation but don't need it anymore.

@Simn
Copy link
Member

Simn commented Nov 9, 2016

Right... Interestingly, the matching function on Java has been deprecated: https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#stop(). I think it's safe to assume that they put more thought into this problem than we did, so following their approach is probably a good idea.

@back2dos
Copy link
Member

back2dos commented Nov 9, 2016

Killing a thread from outside is almost certain to leave behind a big mess. Whatever task the thread performs should have a mechanism built in to safely abort it and clean up any associated resources. In that case there is no doubt some input stream that should be closed and also buffers for the decompression and the resulting image data to be discarded.

As for building such mechanisms one could consider adding an API for interrupts, but I would advise against opening that can of worms. Dequeues provide a suitable messaging abstraction and Haxe is not assembly.

@jdonaldson
Copy link
Member

I remember running into that deprecated method. Here's what they suggest as a workaround:
https://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html

@ncannasse
Copy link
Member

I don't think it's "safe" to stop a thread by simply killing it. You might be in the middle of a sys call with some native resources allocated that will never be freed (like opened files). Using existing threads communication primitives + non blocking or timeout syscalls is the best way to deal with it. For instance haxe.Http does have a timeout if no data is received after some time it will throw an exception.

@Simn
Copy link
Member

Simn commented Nov 25, 2016

I'll go ahead and close this then.

@Simn Simn closed this as completed Nov 25, 2016
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

6 participants