[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH v3 05/12] lib/uksched: Add support for waiting threads
Hi Costin, all, actually, I forgot to raise an important point here: On 3/10/19 9:09 PM, Costin Lupu wrote: +int uk_thread_wait(struct uk_thread *thread) +{ + UK_ASSERT(thread); + + /* TODO critical region */ + + if (thread->detached) + return -1; + + uk_waitq_wait_event(&thread->waiting_threads, is_exited(thread)); + + thread->detached = true; + + uk_sched_thread_destroy(thread->sched, thread); + + return 0; +} If more than one thread waits on the same other thread, then all of those waiting threads will wait in uk_waitq_event(). The first thread that wakes up after the thread has finished will then proceed to destroy the thread management structure. Every other waiting thread will try to do the same after waking up, ending up with duplicate free's and a crash of that thread. That's not very nice.I'm willing to let that slide for now, because the decision was that those thread management functions should align to behavior of the pthread API, and for pthread_join, the documentation explicitly says: "If multiple threads simultaneously try to join with the same thread, the results are undefined." So, technically, this is in line with the design of that function. Nevertheless, I think we ought to revisit that soon, and either don't allow more than one thread to wait (confusingly, even those the specification of pthread_join speaks of undefined behavior, it specifies a return values of EINVAL for "another thread is already waiting to join with this thread"); or to make it so that only the last thrad waking up from the wait queue cleans up. Cheers, Florian -- Dr. Florian Schmidt フローリアン・シュミット Research Scientist, Systems and Machine Learning Group NEC Laboratories Europe Kurfürsten-Anlage 36, D-69115 Heidelberg Tel. +49 (0)6221 4342-265 Fax: +49 (0)6221 4342-155 e-mail: florian.schmidt@xxxxxxxxx ============================================================ Registered at Amtsgericht Mannheim, Germany, HRB728558 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |