[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

17
libc/linux/clone.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef COSMOPOLITAN_LIBC_LINUX_CLONE_H_
#define COSMOPOLITAN_LIBC_LINUX_CLONE_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
forceinline long LinuxClone(unsigned long flags, void* stack, int* parent_tid, int* child_tid, void* tls) {
long rc;
register int* child_tid_ asm("r10") = child_tid;
register void* tls_ asm("r8") = tls;
asm volatile("syscall"
: "=a"(rc)
: "0"(56), "D"(flags), "S"(stack), "d"(parent_tid), "r"(child_tid_), "r"(tls_)
: "rcx", "r11", "memory");
return rc;
}
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_LINUX_MMAP_H_ */