[WIP] Threading (#282)

* Thread creation
* Proper thread creation and exit
* Join/Detach protocol
* Added semaphore with futex (hopefully fast)
This commit is contained in:
Florian Lemaitre 2021-10-13 20:26:05 +02:00 committed by GitHub
parent d852640a1e
commit a0b39f886c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 792 additions and 12 deletions

20
libc/thread/self.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef COSMOPOLITAN_LIBC_THREAD_SELF_H_
#define COSMOPOLITAN_LIBC_THREAD_SELF_H_
#include "libc/thread/descriptor.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/**
* @fileoverview get the thread descriptor of the current thread
*/
inline cthread_t cthread_self(void) {
cthread_t self;
asm ("mov %%fs:0, %0" : "=r"(self));
return self;
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_THREAD_SELF_H_ */