mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Improve pthread_join()
Since we're now on Windows 8, we can have clone() work as advertised on Windows, where it sends a futex wake to the child tid. It's also likely we no longer need to work around thread flakes on OpenBSD, in _wait0().
This commit is contained in:
parent
3733b43a8f
commit
994e1f4386
19 changed files with 154 additions and 74 deletions
|
@ -16,13 +16,10 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/spawn.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
/**
|
||||
* Waits for thread to terminate.
|
||||
|
@ -31,12 +28,15 @@
|
|||
* @raise EDEADLK if thread is detached
|
||||
*/
|
||||
int pthread_join(pthread_t thread, void **value_ptr) {
|
||||
struct PosixThread *pt = (struct PosixThread *)thread;
|
||||
if (pt->status == kPosixThreadDetached || //
|
||||
pt->status == kPosixThreadZombie) {
|
||||
assert(!"badjoin");
|
||||
struct PosixThread *pt;
|
||||
if (thread == __get_tls()->tib_pthread) {
|
||||
return EDEADLK;
|
||||
}
|
||||
if (!(pt = (struct PosixThread *)thread) || //
|
||||
pt->status == kPosixThreadZombie || //
|
||||
pt->status == kPosixThreadDetached) {
|
||||
return EINVAL;
|
||||
}
|
||||
_pthread_wait(pt);
|
||||
if (value_ptr) {
|
||||
*value_ptr = pt->rc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue