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

2016-12-21 19:01 GMT+09:00 Erik Bray <erik.m.bray@gmail.com>:
Above mentioned, In currently TLS API, the thread key uses -1 as defined invalid value. If new TLS API inherits the specifications that the key requires defined invalid value, putting key and flag into one structure seems correct as semantics. In this case, I think TLS API should supply the defined invalid value (like PTHREAD_ONCE_INIT) to API users. Moreover, the structure has an opportunity to assert that the thread key type is the opaque using field name. I think to the suggestion that has effect to improve the understandability of the API because good field name can give that reading and writing to the key seems to be incorrect (even if API users don't read the precautionary statement). Have a nice holiday! Masayuki

Right. Platforms that have a defined invalid value don't need the struct, and so they can define the type differently. It just means we also need to provide a macro for testing whether it's been created or not, and users should genuinely treat the value as opaque. Cheers, Steve Top-posted from my Windows Phone -----Original Message----- From: "Masayuki YAMAMOTO" <ma3yuki.8mamo10@gmail.com> Sent: 12/23/2016 16:34 To: "Erik Bray" <erik.m.bray@gmail.com> Cc: "python-ideas@python.org" <python-ideas@python.org> Subject: Re: [Python-ideas] New PyThread_tss_ C-API for CPython 2016-12-21 19:01 GMT+09:00 Erik Bray <erik.m.bray@gmail.com>: On Wed, Dec 21, 2016 at 2:10 AM, Nick Coghlan <ncoghlan@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; #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. Best, Erik Above mentioned, In currently TLS API, the thread key uses -1 as defined invalid value. If new TLS API inherits the specifications that the key requires defined invalid value, putting key and flag into one structure seems correct as semantics. In this case, I think TLS API should supply the defined invalid value (like PTHREAD_ONCE_INIT) to API users. Moreover, the structure has an opportunity to assert that the thread key type is the opaque using field name. I think to the suggestion that has effect to improve the understandability of the API because good field name can give that reading and writing to the key seems to be incorrect (even if API users don't read the precautionary statement). Have a nice holiday! Masayuki

Right. Platforms that have a defined invalid value don't need the struct, and so they can define the type differently. It just means we also need to provide a macro for testing whether it's been created or not, and users should genuinely treat the value as opaque. Cheers, Steve Top-posted from my Windows Phone -----Original Message----- From: "Masayuki YAMAMOTO" <ma3yuki.8mamo10@gmail.com> Sent: 12/23/2016 16:34 To: "Erik Bray" <erik.m.bray@gmail.com> Cc: "python-ideas@python.org" <python-ideas@python.org> Subject: Re: [Python-ideas] New PyThread_tss_ C-API for CPython 2016-12-21 19:01 GMT+09:00 Erik Bray <erik.m.bray@gmail.com>: On Wed, Dec 21, 2016 at 2:10 AM, Nick Coghlan <ncoghlan@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; #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. Best, Erik Above mentioned, In currently TLS API, the thread key uses -1 as defined invalid value. If new TLS API inherits the specifications that the key requires defined invalid value, putting key and flag into one structure seems correct as semantics. In this case, I think TLS API should supply the defined invalid value (like PTHREAD_ONCE_INIT) to API users. Moreover, the structure has an opportunity to assert that the thread key type is the opaque using field name. I think to the suggestion that has effect to improve the understandability of the API because good field name can give that reading and writing to the key seems to be incorrect (even if API users don't read the precautionary statement). Have a nice holiday! Masayuki
participants (2)
-
Masayuki YAMAMOTO
-
Steve Dower