Question

In solaris when I attached dbx to one of the running stacks, I found the call to fwrite leading to __lll_lock_wait()?

In what scenario will this happen? Does fwrite internally tries to acquire a lock?

Was it helpful?

Solution

the standards that I looked through (C99 and POSIX) do say nothing about locked or unlocked IO concerning fwrite.

On my linux system their is a not very precise mentioning of locking in the man page:

   For non-locking counterparts, see unlocked_stdio(3).

and effectively, there is a fwrite_unlocked function. Standard unlocked functions in POSIX are only getc_unlocked(), getchar_unlocked(), putc_unlocked(), and putchar_unlocked().

My interpretation is that probably all buffered IO in the man(3) set is locked, and that you only have very few standardized interfaces to do unlocked IO.

That these things lock between threads is really a good thing since otherwise you could have completely messy output when several threads write to stderr, e.g.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top