Pali Rohár <[email protected]> wrote:

> On Sunday 21 June 2026 07:59:06 Kirill Makurin wrote:
>> I wrote a test program (attached), and it seems like C89 wc* functions 
>> (wctomb and wcstombs) are really thread-safe on Windows. Even so, 
>> thread-safe code should use `wcrtomb` and `wcsrtombs` instead.
>
> Quite interesting if the wctomb on Windows is really thread safe.

Neither `wctomb` nor `wcrtomb` can be used to convert UTF-16 surrogate paris, 
and as the result it seems like they do not use any conversion state at all. If 
you call them with UTF-16 surrogate, they simply fail. This is actually a real 
problem if you think about it.

> On the other hand, I think that wcstombs should be thread safe on all
> implementations. It needs internal state just on the stack as it is not
> shared with any other followup wcstombs call. And same for mbstowcs.
>
> I was using wcstombs and mbstowcs in this way in multithread apps lot of
> times and I even was not thinking that there could be a problem. So that
> is why I'm surprised if there could be any issues.

I think you're right about; for some I thought that mbstowcs/wcstombs are 
thread-unsafe, just like mbtowc/mblen/wctomb.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to