[Python-ideas] New PyThread_tss_ C-API for CPython

Erik Bray erik.m.bray at gmail.com
Wed Dec 21 05:04:46 EST 2016


On Wed, Dec 21, 2016 at 11:01 AM, Erik Bray <erik.m.bray at gmail.com> wrote:
> That all sounds good--between the two option 2 looks a bit more explicit.
>
> Though what about this?  Rather than adding another type, the original
> proposal could be changed slightly so that Py_tss_t *is* partially
> defined as a struct consisting of a bool, with whatever the native TLS
> key is.   E.g.
>
> typedef struct {
>     bool init_flag;
>     #if defined(_POSIX_THREADS)
>     pthreat_key_t key;

*pthread_key_t* of course, though I wonder if that was a Freudian slip :)

>     #elif defined (NT_THREADS)
>     DWORD key;
>     /* etc... */
> } Py_tss_t;
>
> Then it's just taking Masayuki's original patch, with the global bool
> variables, and formalizing that by combining the initialized flag with
> the key, and requiring the semantics you described above for
> PyThread_tss_create/delete.
>
> For Python's purposes it seems like this might be good enough, with
> the more general purpose pthread_once-like functionality not required.

Of course, that's not to say it might not be useful for some other
purpose, but then it's outside the scope of this discussion as long as
it isn't needed for TLS key initialization.


More information about the Python-ideas mailing list