bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.48k stars 582 forks source link

Attach as Daemon #236

Open masterav10 opened 6 years ago

masterav10 commented 6 years ago

I'd like for the JNI code to attach as a daemon thread. This will allow my applications to cleanly exit when using the hack provided #143. It will also be useful when I finish my bindings for Decklink, which will likely be function pointer based. Does anyone foresee an issue with doing this? I'd be happy to put up a pull request and test it with my build of FFmpeg later this week.

See this line in the generator.

saudet commented 6 years ago

The only thing that makes a deamon thread different from a normal thread is that the JVM will terminate the process even when daemon threads are still running. If that's not an issue for your application or your library, there's nothing special about JavaCPP here. Are you worried about anything in particular?

masterav10 commented 6 years ago

Wasn't sure if exiting while during a callback transition had the potential to cause a JVM crash. I'm guessing this is unlikely to be a problem, as that is the whole point of the daemon. I'll make the change.

saudet commented 6 years ago

Some native libraries might not like it and crash the JVM. That's entirely possible.

saudet commented 6 years ago

So, in the end, have you encountered any issue?

masterav10 commented 6 years ago

I made the change and tested it against my Decklink FFmpeg build. When I go to register the logging callback, it seems to block indefinitely. There are still a couple of things I can try, however. I'll keep you posted.

saudet commented 6 years ago

What does the code look like?