Does fwrite call any lock internally?

只愿长相守 提交于 2019-12-01 09:51:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3685115/does-fwrite-call-any-lock-internally

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!