Odd... I sent this to the ML a couple of weeks ago, but it doesn't seem to
have made it out...
Alan
--
Hello, all.
As previously reported, I've been trying to track down
a deadlock condition in the ThreadState regression test (among others)
whereby one or more threads attempt to acquire a ksem that they already
hold. I develop and test on a dual-processor machine (although I can
reproduce the problem with one of the processors turned off).
As implemented, the ksem functions are trivially implemented
as described in FAQ.locks, using BeOS's native counting semaphores.
I added some DBG calls to the ksem funcs, ran ThreadState with
arguments "-v 2", and obtained the following (annotations are mine,
and "Kaffe main thread" is that thread which is "created" by
jthread_createfirst()):
==
main thread has id 261a
Kaffe main thread: created sem 94431 /* object lock */
Kaffe main thread: created sem 94435 /* finMan */
created thread finaliser, daemon=1
Kaffe main thread: created sem 94439 /* gcMan */
start_me_up: setting up for finaliser
start_me_up: calling t-func for finaliser
finaliser: attempting to acquire sem 94435
created thread gc, daemon=1
start_me_up: setting up for gc
start_me_up: calling t-func for gc
gc: attempting to acquire sem 94439
Kaffe main thread: created sem 94443
created thread Thread-0, daemon=0
start_me_up: setting up for Thread-0
start_me_up: calling t-func for Thread-0
Thread-0: attempting to acquire sem 94443
Kaffe main thread: releasing sem 94443
Thread-0: acquired sem 94443
Kaffe main thread: releasing sem 94443
Kaffe main thread: created sem 94447
created thread Thread-1, daemon=0
Thread-0: attempting to acquire sem 94443
Thread-0: acquired sem 94443 /* OK, 94443 belongs to T-0 */
start_me_up: setting up for Thread-1
start_me_up: calling t-func for Thread-1
Thread-1: attempting to acquire sem 94447
Kaffe main thread: releasing sem 94447
Thread-1: acquired sem 94447
Thread-1: attempting to acquire sem 94447
Kaffe main thread: attempting to acquire sem 94431
Thread-0: attempting to acquire sem 94443 /* T-0 wants 94443 again?! */
Thread-0: releasing sem 94431
Kaffe main thread: acquired sem 94431
Thread-0: releasing sem 94447
Thread-1: acquired sem 94447
Thread-1: attempting to acquire sem 94447
Thread-0: attempting to acquire sem 94443
Kaffe main thread: releasing sem 94443
Thread-0: acquired sem 94443
Thread-0: releasing sem 94447
Thread-1: acquired sem 94447
Thread-0: attempting to acquire sem 94443
Thread-1: attempting to acquire sem 94447
Kaffe main thread: releasing sem 94447
Thread-1: acquired sem 94447
Kaffe main thread: attempting to acquire sem 94431
Thread-1: releasing sem 94443
Thread-0: acquired sem 94443
Thread-0: created sem 94451
created thread Thread-2, daemon=0
Thread-1: created sem 94455
Thread-1: attempting to acquire sem 94447
start_me_up: setting up for Thread-2
start_me_up: calling t-func for Thread-2
Thread-2: attempting to acquire sem 94451
Thread-0: releasing sem 94451
Thread-2: acquired sem 94451
Thread-2: releasing sem 94447
Thread-1: acquired sem 94447
created thread Thread-3, daemon=0
Thread-2: attempting to acquire sem 94451
Thread-0: releasing sem 94451
start_me_up: setting up for Thread-3
start_me_up: calling t-func for Thread-3
Thread-3: attempting to acquire sem 94455
Thread-1: releasing sem 94455
Thread-2: acquired sem 94451
Thread-3: acquired sem 94455
Thread-3: attempting to acquire sem 94455
Thread-1: attempting to acquire sem 94447
Thread-2: destroyed sem 94451
jthread_exit called by Thread-2
Removing entry for thread Thread-2
Thread-2: attempting to acquire sem 94451
Thread-2: failed to acquire sem 94451
Thread-2: attempting to acquire sem 94451
Thread-2: failed to acquire sem 94451
Thread-2: attempting to acquire sem 94451
Thread-2: failed to acquire sem 94451
Thread-2: attempting to acquire sem 94451
Thread-2: failed to acquire sem 94451/* T-2 failed to get 94451 */
Thread-2: releasing sem 94451/* so why is it releasing it */
Thread-2: at the point of no return in jthread_exit
Thread-0: releasing sem 94451
Success.
Thread-0: releasing sem 94431
Kaffe main thread: acquired sem 94431
Kaffe main thread: attempting to acquire sem 94431
Thread-0: destroyed sem 94443
jthread_exit called by Thread-0
Removing entry for thread Thread-0
Thread-0: at the point of no return in jthread_exit
==
/boot/usr/kaffe/libexec/Kaffe -vmdebug JTHREAD ThreadState 2 (team 6787) (uid 0) (gid
0)
9754Kaffe main thread sem 11 8091469 Ksem(94431)
9759finaliser sem 20 0 0 Ksem(94435)
9760 gc sem 20 0 0 Ksem(94439)
9762 Thread-1 sem 11 1 2 Ksem(94447)
9764 Thread-3 sem 11 0 0 Ksem(94455)
Kaffe main thread in java_lang_Object_wait0:w