mailing list of musl libc
 help / color / mirror / code / Atom feed
* thread local should be used
@ 2015-05-08  7:36 罗勇刚(Yonggang Luo) 
  2015-05-08  7:51 ` Jens Gustedt
  0 siblings, 1 reply; 5+ messages in thread
From: 罗勇刚(Yonggang Luo)  @ 2015-05-08  7:36 UTC (permalink / raw)
  To: musl

218933012b1f0f052f91ac39ee5cc6daba99237d
 src/multibyte/mbrtowc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
index e7b3654..de8d5ae 100644
--- a/src/multibyte/mbrtowc.c
+++ b/src/multibyte/mbrtowc.c
@@ -8,15 +8,15 @@
 #include <errno.h>
 #include "internal.h"

+_Thread_local static mbstate_t internal_state;
 size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t
n, mbstate_t *restrict st)
 {
- static unsigned internal_state;
  unsigned c;
  const unsigned char *s = (const void *)src;
  const unsigned N = n;
  wchar_t dummy;

- if (!st) st = (void *)&internal_state;
+ if (!st) st = &internal_state;
  c = *(unsigned *)st;

  if (!s) {

-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: thread local should be used
  2015-05-08  7:36 thread local should be used 罗勇刚(Yonggang Luo) 
@ 2015-05-08  7:51 ` Jens Gustedt
  2015-05-08  7:53   ` 罗勇刚(Yonggang Luo) 
  0 siblings, 1 reply; 5+ messages in thread
From: Jens Gustedt @ 2015-05-08  7:51 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1487 bytes --]

Hello,
certainly not.

First of all _Thread_local is a C11 feature, out of reach for a
portable library implementation still for some years.

Then the requirement that this is a static state per function is a
fixed requirement in the standard. No way out of that.

Jens

Am Freitag, den 08.05.2015, 15:36 +0800 schrieb 罗勇刚(Yonggang Luo) :
> 218933012b1f0f052f91ac39ee5cc6daba99237d
>  src/multibyte/mbrtowc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
> index e7b3654..de8d5ae 100644
> --- a/src/multibyte/mbrtowc.c
> +++ b/src/multibyte/mbrtowc.c
> @@ -8,15 +8,15 @@
>  #include <errno.h>
>  #include "internal.h"
> 
> +_Thread_local static mbstate_t internal_state;
>  size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t
> n, mbstate_t *restrict st)
>  {
> - static unsigned internal_state;
>   unsigned c;
>   const unsigned char *s = (const void *)src;
>   const unsigned N = n;
>   wchar_t dummy;
> 
> - if (!st) st = (void *)&internal_state;
> + if (!st) st = &internal_state;
>   c = *(unsigned *)st;
> 
>   if (!s) {
> 


-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::




[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: thread local should be used
  2015-05-08  7:51 ` Jens Gustedt
@ 2015-05-08  7:53   ` 罗勇刚(Yonggang Luo) 
  2015-05-08  7:56     ` 罗勇刚(Yonggang Luo) 
  0 siblings, 1 reply; 5+ messages in thread
From: 罗勇刚(Yonggang Luo)  @ 2015-05-08  7:53 UTC (permalink / raw)
  To: musl

Does that need to be thread safe for the static state?

2015-05-08 15:51 GMT+08:00 Jens Gustedt <jens.gustedt@inria.fr>:
> Hello,
> certainly not.
>
> First of all _Thread_local is a C11 feature, out of reach for a
> portable library implementation still for some years.
>
> Then the requirement that this is a static state per function is a
> fixed requirement in the standard. No way out of that.
>
> Jens
>
> Am Freitag, den 08.05.2015, 15:36 +0800 schrieb 罗勇刚(Yonggang Luo) :
>> 218933012b1f0f052f91ac39ee5cc6daba99237d
>>  src/multibyte/mbrtowc.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
>> index e7b3654..de8d5ae 100644
>> --- a/src/multibyte/mbrtowc.c
>> +++ b/src/multibyte/mbrtowc.c
>> @@ -8,15 +8,15 @@
>>  #include <errno.h>
>>  #include "internal.h"
>>
>> +_Thread_local static mbstate_t internal_state;
>>  size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t
>> n, mbstate_t *restrict st)
>>  {
>> - static unsigned internal_state;
>>   unsigned c;
>>   const unsigned char *s = (const void *)src;
>>   const unsigned N = n;
>>   wchar_t dummy;
>>
>> - if (!st) st = (void *)&internal_state;
>> + if (!st) st = &internal_state;
>>   c = *(unsigned *)st;
>>
>>   if (!s) {
>>
>
>
> --
> :: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
> :: ::::::::::::::: office Strasbourg : +33 368854536   ::
> :: :::::::::::::::::::::: gsm France : +33 651400183   ::
> :: ::::::::::::::: gsm international : +49 15737185122 ::
> :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
>
>
>



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: thread local should be used
  2015-05-08  7:53   ` 罗勇刚(Yonggang Luo) 
@ 2015-05-08  7:56     ` 罗勇刚(Yonggang Luo) 
  2015-05-08  8:26       ` Jens Gustedt
  0 siblings, 1 reply; 5+ messages in thread
From: 罗勇刚(Yonggang Luo)  @ 2015-05-08  7:56 UTC (permalink / raw)
  To: musl

OK, I understand, cause the pst doesn't return, so the value in it
doesn't matter.

2015-05-08 15:53 GMT+08:00 罗勇刚(Yonggang Luo) <luoyonggang@gmail.com>:
> Does that need to be thread safe for the static state?
>
> 2015-05-08 15:51 GMT+08:00 Jens Gustedt <jens.gustedt@inria.fr>:
>> Hello,
>> certainly not.
>>
>> First of all _Thread_local is a C11 feature, out of reach for a
>> portable library implementation still for some years.
>>
>> Then the requirement that this is a static state per function is a
>> fixed requirement in the standard. No way out of that.
>>
>> Jens
>>
>> Am Freitag, den 08.05.2015, 15:36 +0800 schrieb 罗勇刚(Yonggang Luo) :
>>> 218933012b1f0f052f91ac39ee5cc6daba99237d
>>>  src/multibyte/mbrtowc.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/multibyte/mbrtowc.c b/src/multibyte/mbrtowc.c
>>> index e7b3654..de8d5ae 100644
>>> --- a/src/multibyte/mbrtowc.c
>>> +++ b/src/multibyte/mbrtowc.c
>>> @@ -8,15 +8,15 @@
>>>  #include <errno.h>
>>>  #include "internal.h"
>>>
>>> +_Thread_local static mbstate_t internal_state;
>>>  size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t
>>> n, mbstate_t *restrict st)
>>>  {
>>> - static unsigned internal_state;
>>>   unsigned c;
>>>   const unsigned char *s = (const void *)src;
>>>   const unsigned N = n;
>>>   wchar_t dummy;
>>>
>>> - if (!st) st = (void *)&internal_state;
>>> + if (!st) st = &internal_state;
>>>   c = *(unsigned *)st;
>>>
>>>   if (!s) {
>>>
>>
>>
>> --
>> :: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
>> :: ::::::::::::::: office Strasbourg : +33 368854536   ::
>> :: :::::::::::::::::::::: gsm France : +33 651400183   ::
>> :: ::::::::::::::: gsm international : +49 15737185122 ::
>> :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
>>
>>
>>
>
>
>
> --
>          此致
> 礼
> 罗勇刚
> Yours
>     sincerely,
> Yonggang Luo



-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: thread local should be used
  2015-05-08  7:56     ` 罗勇刚(Yonggang Luo) 
@ 2015-05-08  8:26       ` Jens Gustedt
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Gustedt @ 2015-05-08  8:26 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 821 bytes --]

Am Freitag, den 08.05.2015, 15:56 +0800 schrieb 罗勇刚(Yonggang Luo) :
> OK, I understand, cause the pst doesn't return, so the value in it
> doesn't matter.

I am not sure that I understand what you are saying, but you have to
see that implementing a standard C library has much less flexibility
than implementing your own interface. We have to exacly match the
requirements of the standard, and for this state variable they are
clear and precise: implement a static state per such function.

Jens

-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::




[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-08  8:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-08  7:36 thread local should be used 罗勇刚(Yonggang Luo) 
2015-05-08  7:51 ` Jens Gustedt
2015-05-08  7:53   ` 罗勇刚(Yonggang Luo) 
2015-05-08  7:56     ` 罗勇刚(Yonggang Luo) 
2015-05-08  8:26       ` Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).