Issue with a thread seemingly being dead but pthread_kill( p, 0 ) still returns 0

308 views
Skip to first unread message

Timo Heinäpurola

unread,
Mar 17, 2012, 11:27:12 AM3/17/12
to android-ndk
Hi,

The issue is, as the subject already explains, that at some point
during my application's lifecycle a specific thread seems to die
somehow. No signal is sent that would result in its termination. The
entry point is not returning but I can't see it in the GDB thread list
anymore. The application does not crash but a wait loop that also
checks for whether the thread is still alive or not (by using
pthread_kill( p, 0 )) keeps on rolling. It's as if the thread is still
somehow alive but then again, from pthread's point of view, it's
not...

Even worse, the whole phone seems to hang but I can still attach the
debugger and see this happening. When the process is killed by the
debugger, the phone boots. I'm using an HTC Desire phone with Android
2.3.

Any ideas?

Best regards,
Timo Heinäpurola
Raccoon Interactive Oy

Timo Heinäpurola

unread,
Mar 17, 2012, 4:26:25 PM3/17/12
to android-ndk
Some additional information here.

It appears that the freeze happens due to Android waiting for event
handlers like onResume etc. to return. The problem is that I use the
default app glue code which waits for conditional variables that are
broadcast in event handlers but those broadcasts are never reached as
the thread that keeps on waiting for the dead thread is also the same
thread that should signal the variable.

The bottom line now is that I still have absolutely no clue as to why
pthread thinks the thread still exists even though it does not...

Best regards,
Timo Heinäpurola
Raccoon Interactive Oy

On 17 maalis, 17:27, Timo Heinäpurola <timo.heinapur...@live.com>
wrote:

badcc0de

unread,
Mar 18, 2012, 10:55:29 AM3/18/12
to android-ndk
To me it sounds like a deadlock issue, I have had threads on Android
and even full desktop issues that fail to show up in GDB because their
so "borked"; they seem to return fine, but somewhere in the pthreads
code this happens? Also, what is your return code from
pthread_kill(tid, 0); ?

On Mar 17, 12:26 pm, Timo Heinäpurola <timo.heinapur...@live.com>
wrote:

badcc0de

unread,
Mar 18, 2012, 11:05:36 AM3/18/12
to android-ndk
Ok I see that it pthread_kill returns 0 as indicated in the subject
line. My guess is deadlock and thread is not exiting cleanly. Rather
than polling the thread to see if it is alive, if the thread your
waiting on is started in a "joined" state (which is the default
attributes for pthread_create), then you should really be using
pthread_join.

Timo Heinäpurola

unread,
Mar 18, 2012, 5:19:08 PM3/18/12
to android-ndk
Hi,

The issue was actually a bit different from what I originally thought
it to be. It was eglSwapBuffers that deadlocked and is a known issue
in Android: http://code.google.com/p/android/issues/detail?id=20833.
But anyway, the thread had deadlocked due to eglSwapBuffers, so in
that sense you were spot on. I'm not joining the thread. I'm just
checking for a situation where the thread might have abnormally
exited. I do have a flag that is set when the thread exits but I
wanted to be sure. But then again, abnormal termination would hit the
whole process, so I guess I'm good :)

Thanks,
Timo Heinäpurola
Raccoon Interactive Oy

Reply all
Reply to author
Forward
0 new messages