* Thread-safety of iconv()
@ 2014-09-15 9:32 Marko Myllynen
[not found] ` <5416B235.8020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Marko Myllynen @ 2014-09-15 9:32 UTC (permalink / raw)
To: Michael Kerrisk (man-pages), Peng Haitao; +Cc: linux-man, Carlos O'Donell
Hi Michael, Haitao,
iconv(3) states:
ATTRIBUTES
Multithreading (see pthreads(7))
The iconv() function is thread-safe.
But iconv_open(3) says:
A conversion descriptor contains a conversion state. After creation
using iconv_open(), the state is in the initial state. Using iconv(3)
modifies the descriptor's conversion state. (This implies that a con-
version descriptor can not be used in multiple threads simultaneously.)
To bring the state back to the initial state, use iconv(3) with NULL as
inbuf argument.
This looks a bit unclear, do you think you could clarify iconv(3) and/or
iconv_open(3) a bit in thread-safety regard?
Thanks,
--
Marko Myllynen
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <5416B235.8020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>]
* Re: Thread-safety of iconv() [not found] ` <5416B235.8020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> @ 2014-09-18 6:50 ` Peng Haitao [not found] ` <541A80BD.8050509-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Peng Haitao @ 2014-09-18 6:50 UTC (permalink / raw) To: myllynen-H+wXaHxf7aLQT0dZR+AlfA, Michael Kerrisk (man-pages) Cc: linux-man, Carlos O'Donell On 09/15/2014 05:32 PM, Marko Myllynen wrote: > Hi Michael, Haitao, > > iconv(3) states: > > ATTRIBUTES > Multithreading (see pthreads(7)) > The iconv() function is thread-safe. > > But iconv_open(3) says: > > A conversion descriptor contains a conversion state. After creation > using iconv_open(), the state is in the initial state. Using iconv(3) > modifies the descriptor's conversion state. (This implies that a con- > version descriptor can not be used in multiple threads simultaneously.) > To bring the state back to the initial state, use iconv(3) with NULL as > inbuf argument. > > This looks a bit unclear, do you think you could clarify iconv(3) and/or > iconv_open(3) a bit in thread-safety regard? > Yes, I will clarify it. When calling iconv() as iconv(cd, inbuf, ...) and iconv(cd, NULL, ...) in multiple threads simultaneously, Segmentation fault may occur. So, I think the glibc's level "MT-Safe race:cd" is good. http://www.gnu.org/software/libc/manual/html_mono/libc.html#index-iconv-1 Thanks. -- Best Regards, Peng -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <541A80BD.8050509-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>]
* Re: Thread-safety of iconv() [not found] ` <541A80BD.8050509-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> @ 2014-09-18 13:14 ` Carlos O'Donell [not found] ` <541ADAC1.2090108-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 0 siblings, 1 reply; 4+ messages in thread From: Carlos O'Donell @ 2014-09-18 13:14 UTC (permalink / raw) To: Peng Haitao, myllynen-H+wXaHxf7aLQT0dZR+AlfA, Michael Kerrisk (man-pages) Cc: linux-man, Alexandre Oliva On 09/18/2014 02:50 AM, Peng Haitao wrote: > On 09/15/2014 05:32 PM, Marko Myllynen wrote: >> Hi Michael, Haitao, >> >> iconv(3) states: >> >> ATTRIBUTES >> Multithreading (see pthreads(7)) >> The iconv() function is thread-safe. >> >> But iconv_open(3) says: >> >> A conversion descriptor contains a conversion state. After creation >> using iconv_open(), the state is in the initial state. Using iconv(3) >> modifies the descriptor's conversion state. (This implies that a con- >> version descriptor can not be used in multiple threads simultaneously.) >> To bring the state back to the initial state, use iconv(3) with NULL as >> inbuf argument. >> >> This looks a bit unclear, do you think you could clarify iconv(3) and/or >> iconv_open(3) a bit in thread-safety regard? It is conditionally thread safe :-) >> > > Yes, I will clarify it. > > When calling iconv() as iconv(cd, inbuf, ...) and iconv(cd, NULL, ...) > in multiple threads simultaneously, Segmentation fault may occur. > > So, I think the glibc's level "MT-Safe race:cd" is good. > http://www.gnu.org/software/libc/manual/html_mono/libc.html#index-iconv-1 The `cd' object is opaque to the user, and therefore in the glibc manual Alex and I felt it was appropriate to call out that it *is* thread safe to call this function but that the `iconv_t`-type object `cd` has itself no locking and can be corrupted by multiple calls with the same object, hence `race:cd` e.g. there is a data-race calling this function with the same cd object. Alex, please correct me if I'm wrong, but I think that sums it up. Cheers, Carlos. -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <541ADAC1.2090108-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>]
* Re: Thread-safety of iconv() [not found] ` <541ADAC1.2090108-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> @ 2014-09-19 2:57 ` Alexandre Oliva 0 siblings, 0 replies; 4+ messages in thread From: Alexandre Oliva @ 2014-09-19 2:57 UTC (permalink / raw) To: Carlos O'Donell Cc: Peng Haitao, myllynen-H+wXaHxf7aLQT0dZR+AlfA, Michael Kerrisk (man-pages), linux-man On Sep 18, 2014, "Carlos O'Donell" <carlos-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote: > On 09/18/2014 02:50 AM, Peng Haitao wrote: >> On 09/15/2014 05:32 PM, Marko Myllynen wrote: >>> This looks a bit unclear, do you think you could clarify iconv(3) and/or >>> iconv_open(3) a bit in thread-safety regard? > It is conditionally thread safe :-) It is MT-Safe, but it assumes callers arrange for mutual exclusion on the cd object passed as argument. It is no different from e.g. memset being MT-Safe, in spite of the race when two threads call memset concurrently, writing to the same buffer. It's caller's responsibility to avoid such races in both cases. > Alex, please correct me if I'm wrong, but I think that sums it up. Yup. A recent blog post covers this issue (among others) in some detail: http://developerblog.redhat.com/2014/09/10/multi-thread-async-signal-and-async-cancel-safety-docs-in-gnu-libc/ -- Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/ You must be the change you wish to see in the world. -- Gandhi Be Free! -- http://FSFLA.org/ FSF Latin America board member Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-19 2:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-15 9:32 Thread-safety of iconv() Marko Myllynen
[not found] ` <5416B235.8020309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-09-18 6:50 ` Peng Haitao
[not found] ` <541A80BD.8050509-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2014-09-18 13:14 ` Carlos O'Donell
[not found] ` <541ADAC1.2090108-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-09-19 2:57 ` Alexandre Oliva
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox