#4888: proposal for pthreads extensions for suspend/resume --------------------------------+------------------------------------------- Reporter: andrewbachmann | Owner: axeld Type: enhancement | Status: closed Priority: normal | Milestone: R1 Component: System/libroot.so | Version: Resolution: invalid | Keywords: Blockedby: | Platform: All Blocking: | --------------------------------+------------------------------------------- Comment(by bonefish): Replying to [comment:9 andrewbachmann]: > In OpenJDK, in os_solaris.[hc]pp the methods thr_create and thr_continue are used to create and start the pthreads corresponding to java threads. thr_create is called with a flag to start suspended, which allows for reliable and straightforward java thread initiation. If this is only about thread initialization and it is for some reason not possible to do that initialization before actually creating the thread, you could simply use a wrapper function for the thread entry function. If, for some reason, the initialization has to happen in the thread creating the new thread, you could still use a standard locking primitive, like a mutex, to synchronize the two. Like in the creating thread: - create mutex - lock mutex - create thread - do initialization - unlock mutex And in the thread entry wrapper function: - lock mutex - destroy mutex - call actual thread function > With the addition of the get_pthread_thread_id(), I am fine with not supplying pthread_suspend and pthread_continue. It does seem odd to require a pthread-oriented program to go through the thread_id in order to perform this functionality. You actually don't even have to, since you could just use pthread_kill() with SIGSTOP and SIGCONT. I don't quite see, how that would already help with your initialization issue -- you'll have a huge race condition between creating the thread and suspending it. Unless you use something like I proposed above, but then I wouldn't see the need for suspending anymore. > I believe my proposal is the simplest and smallest change to provide the functionality used by OpenJDK. Yeah, I agree with Axel, though, that we usually don't just add stuff to a standard (that's one of the things that makes standards suck). There are exceptions like when something is already used by several OSs and is thus a quasi-standard extension. Replying to [comment:10 stippi]: > Axel recently changed threads so every native Haiku thread is also a pthread now. Don't know if a "convert_to_pthread()" is still needed or not. But I thought that IDs are now interchangeable. Pthreads don't have IDs, they are represented by a pthread object. So you'd still need to get the object pointer by thread_id, which is what the function would mainly do. It should also alter the detached state of the pthread. Normally (i.e. unless auto-detaching has specifically been requested) the pthread object lives on after the thread died -- it will be destroyed after a pthread_join() (the equivalent to a wait_for_thread()). Standard Haiku threads are auto-detached, so it would not be safe for other threads to play with their pthread object. -- Ticket URL: <http://dev.haiku-os.org/ticket/4888#comment:11> Haiku <http://dev.haiku-os.org> Haiku - the operating system.