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

Use one thread for all callbacks #125

Open
deripas opened this issue Jun 27, 2017 · 4 comments
Open

Use one thread for all callbacks #125

deripas opened this issue Jun 27, 2017 · 4 comments

Comments

@deripas
Copy link

deripas commented Jun 27, 2017

I have simple library with API:

    interface OnImage {
        @Delegate
        void callback(int width, int height, Pointer buff);
    }

    void open(Pointer cam, OnImage callback);

Each callback call create a new java thread to handle the callback. How I can handle callback in fixed/single thread?
In JNA can use CallbackThreadInitializer:

Native.setCallbackThreadInitializer(callback, new CallbackThreadInitializer());

What analogy in JNR?
Thank!

@ghost
Copy link

ghost commented Jun 30, 2017

Wow, coincidence on the timing.

I've been using this library for 6 months and just realised I'm seeing the same thing and was about to raise an issue.

@ghost
Copy link

ghost commented Jul 2, 2017

As far as I can see, this issue should be moved to https://github.com/jnr/jffi

It looks like ClosureMagazine.c method closure_invoke(...) needs to support configuring the behaviour of the thread attach/detach logic. Currently if possible to attach the thread before invocation it is always detached after invocation.

@headius
Copy link
Member

headius commented Aug 4, 2017

Yes this should be a jffi issue most likely, and I agree it should be fixed. We should do a round of patches.

The unfortunate part of having to change the C code is rebuilding the native library for all platforms, so this fix would require a pretty major release.

@re-thc
Copy link

re-thc commented Jun 7, 2018

Any chance of getting a fix for this?

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

3 participants