Does fwrite call any lock internally?

后端 未结 1 1127
北荒
北荒 2021-01-16 04:01

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

相关标签:
1条回答
  • 2021-01-16 04:19

    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.

    0 讨论(0)
提交回复
热议问题