[m-dev.] Interleaved output in hlc.gc.par
zoltan.somogyi at runbox.com
Thu Sep 17 19:49:21 AEST 2015
On Thu, 17 Sep 2015 18:09:18 +1000, Paul Bone <paul at bone.id.au> wrote:
> I don't know about sprintf, but I believe that printf and fprintf are thread
> safe, or maybe that's just glibc..
That is not something you want to just "believe".
> I just checked runtime/mercury_string.c and MR_make_string which is where
> the call to vsnprintf or vsprintf is done (called from string.format.m).
> The buffer is either allocated on the stack or the heap (depending on it's
> size requirements) and never statically allocated. The procedure is thread
> safe and reentrant.
> So this formats the string using a thread-safe buffer, then write_string
> writes it out, this eventually calls vfprintf to write the string.
That is NOT the buffer I am talking about. I am talking about the buffer
that stdio associates with every file descriptor that is either opened
by stdio itself using fopen or its relatives, or is one of stdin/out/err,
for which stdio creates a buffer at startup.
> Ultimately the thread-safety of this depends on libc, and I believe that
> with glibc this is thread safe (but obviously shouldn't be relied on).
A brief google search told me that this is VERY OS-dependent.
More information about the developers