Sending signal from native thread to SDK thread

263 views
Skip to first unread message

B Zen

unread,
Apr 6, 2010, 9:28:02 PM4/6/10
to android-ndk
Hi,

I am trying to send a signal from a native thread (created via
pthread_create()) to the SDK thread.

Here is how I'm doing it:

- In the JNI method that is invoked from SDK space, create a native
thread using pthread_create().
- Now wait inside the JNI method using sigwait(). This wait is
happening in the SDK thread context.
- Have the newly created native thread send a signal(SIGUSR1) to SDK
thread via pthread_kill()

The pthread_kill() call from native thread fails with error EPERM.

If I try to send the same signal from SDK thread to the native thread,
it works fine. The pthread_kill() call succeeds and the native thread
is woken up correctly in this case.

Is it possible to send signal to SDK thread from NDK thread? Is there
any other way of sending signal except pthread_kill()?

Thanks
B

David Turner

unread,
Apr 6, 2010, 9:40:26 PM4/6/10
to andro...@googlegroups.com
Why are you using signals anyway, they suck enormously for a variety of reasons.
What are you trying to achieve here ?


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


David Turner

unread,
Apr 6, 2010, 9:41:42 PM4/6/10
to andro...@googlegroups.com
the EPERM error probably comes from the fact that you don't have the pthread_t of the SDK thread, but something else.

B Zen

unread,
Apr 6, 2010, 10:27:17 PM4/6/10
to android-ndk
I think that makes sense.
The reason I'm using signals has more to do with leveraging existing
code and execution logic than anything else. I think conditional
variables could be another way to achieve inter-thread communication.
I'm gonna try that if I don't get other responses to my query.
Thanks!
B

On Apr 6, 6:41 pm, David Turner <di...@android.com> wrote:
> the EPERM error probably comes from the fact that you don't have the
> pthread_t of the SDK thread, but something else.
>
> On Tue, Apr 6, 2010 at 6:40 PM, David Turner <di...@android.com> wrote:
> > Why are you using signals anyway, they suck enormously for a variety of
> > reasons.
> > What are you trying to achieve here ?
>

> > On Tue, Apr 6, 2010 at 6:28 PM, B Zen <biren...@gmail.com> wrote:
>
> >> Hi,
>
> >> I am trying to send a signal from a native thread (created via
> >> pthread_create()) to the SDK thread.
>
> >> Here is how I'm doing it:
>
> >> - In the JNI method that is invoked from SDK space, create a native
> >> thread using pthread_create().
> >> - Now wait inside the JNI method using sigwait(). This wait is
> >> happening in the SDK thread context.
> >> - Have the newly created native thread send a signal(SIGUSR1) to SDK
> >> thread via pthread_kill()
>
> >> The pthread_kill() call from native thread fails with error EPERM.
>
> >> If I try to send the same signal from SDK thread to the native thread,
> >> it works fine. The pthread_kill() call succeeds and the native thread
> >> is woken up correctly in this case.
>
> >> Is it possible to send signal to SDK thread from NDK thread? Is there
> >> any other way of sending signal except pthread_kill()?
>
> >> Thanks
> >> B
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "android-ndk" group.
> >> To post to this group, send email to andro...@googlegroups.com.
> >> To unsubscribe from this group, send email to

> >> android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages