[kaffe] Possibly Bug In the implementation of jcondvar_broadcast function
Guilhem Lavaux
guilhem at kaffe.org
Wed Jun 2 12:46:02 PDT 2004
dai shaowei wrote:
> Dear Jim Pick:
> I am currently analysing the source code of Kaffe,I find there are
> possibly something wrong in the implemention of the function
> "jcondvar_broadcast"and "jthread_stop" in
> kaffe -1.1.4\kaffe\kaffevm\systems\unix-jhtreads,following is the source
> code
>
> I think the correct implementation should be :
> Your Orginal code: for (condp = cv; *condp != 0; condp = &(*condp)->next)
> ;
> (*condp) = lock->waiting;
> lock->waiting = *condp;
> My Corrected code: for (condp = cv; (*condp)->next != 0; condp =
> &(*condp)->next)
> ;
> (*condp) ->next = lock->waiting;
> lock->waiting = *cv; after the "for" repeating
> clause,*condp == 0,this cause the node in the cv can't link the lock
> waiting queue,and after the link ,we should set the lock->waiting to be
> the first element of the new queue,am I right? hoping your reply.
>
Hi !
I agree there is a bug here. We are basically doing lock->waiting =
lock->waiting which is wrong. However I believe that the loop is right
(though your code may also work). When the loop exits, condp points to
the last (*condp)->next variable (which is NULL by the loop condition.
So we can assign it to lock->waiting by dereferencing condp. However
lock->waiting should be assigned to the first node of the queue, that is
*cv.
I think that when I modified that code I have made an extra copy-paste. ;-)
> Your source code:
> if (jtid == jthread_current() && (jtid->flags &
> THREAD_FLAGS_DONTSTOP) != 0 && blockInts == 1)
> die();
> My corrected code:
> if (jtid == jthread_current() && (jtid->flags &
> THREAD_FLAGS_DONTSTOP) == 0 && blockInts == 1)
> die();
> because only when we can stop a thread(the flag THREAD_FLAGS_DONTSTOP is
> not set) ,we should call the die(),otherwise,we can only resume the thread
> I don’t know whether my understanding is right, I would be very glad
> if you tell me your viewpoint.
I agree with that point.
Thank you very much !
Regards,
Guilhem Lavaux.
More information about the kaffe
mailing list