summaryrefslogtreecommitdiff
path: root/lib/thread/spawn+freebsd.myr
AgeCommit message (Collapse)Author
2018-10-25Heapify closures on OSX/FreeBSD.Ori Bernstein
Fixes tests. (Thanks, iri)
2018-10-18Add thread-local storage for POSIX-y platforms.iriri
This patch implements thread-local storage by using a segment register to store pointers to regions of memory unique to each thread. In spawned threads, this region starts above the top of the stack, while in the main thread, this region is initially statically allocated so it can be used in `__init__` functions and dynamically reallocated if it needs to grow beyond 8 slots. The api consists of 3 functions: `tlsalloc()`, which must be called from the main thread, allocates a slot and returns a key to be used with `settls(k, v)` and `gettls(k)`. Each thread inherits its tls slots from the thread that spawned it and any slot added after a given thread is spawned is not available in that thread. Adding tls regions gives threads an easy way to get their own tids, allowing us to add some basic correctness checks to the mutex code. A pointer to the base of the stack and the size of the mapping are also stored in the tls region, making it easy to support user-specified stack sizes in the future. Changes from previous version: - Fixed size of main tls static allocation. - More comments, less magic. - Fixed typo in start+osx-x64.s exit+{freebsd,linux,openbsd}-x64.s - `gettlskey` renamed to `tlsalloc`. - `key` is now `tlskey(@a#)`, improving safety. - Test is slightly less bad.
2017-04-22Reserve stack space for the environment.Ori Bernstein
We copied it, but then clobbered it. Shit.
2017-04-09Duplicate env on thread spawn.Ori Bernstein
2016-08-27Rename `std.Fail to `std.Err.Ori Bernstein
2016-05-17New syntax for casts.Ori Bernstein
2015-12-14Spawn and exit on FreeBSDOri Bernstein