Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add thread-local storage for POSIX-y platforms.


On Sat, 13 Oct 2018 13:58:52 -0700, iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> 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.

Merged.

-- 
    Ori Bernstein

References:
[PATCH] Add thread-local storage for POSIX-y platforms.iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
[PATCH] Add thread-local storage for POSIX-y platforms.iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Re: [PATCH] Add thread-local storage for POSIX-y platforms.Ori Bernstein <ori@xxxxxxxxxxxxxx>
[PATCH] Add thread-local storage for POSIX-y platforms.iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>