This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: thread safety level of fwide


On 11/20/2014 04:32 AM, Alexandre Oliva wrote:
> The uses of fp, although technically racy, are well-defined, because of
> the way stream orientation works: once it's decided, it never changes,
> so it is safe to test, before taking a lock, whether it is already
> decided and use the settled value if so.  It is only if it is not
> decided yet (when _mode is zero) and we want to set a value (when mode
> is nonzero) that we have to resort to mutual exclusion to serialize mode
> settings.

I think I got the point.
> It is only if it is not
> decided yet (when _mode is zero) and we want to set a value (when mode
> is nonzero) that we have to resort to mutual exclusion to serialize mode
> settings.
That's what I take care about.
If it hasn't be decided (when _mode is zero), and there are two threads.
Thread A wants to set _mode as 1.
Thread B wants to set _mode as -1.
Perhaps thread A has just checked fp->_mode and before set it to 1, thread B set
fp->_mode to -1 more first.
Just like:
thread A      fp->_mode   thread B
   |              |          |
   |              |          |
   v              v          v
check _mode    value 0    check _mode
   |              |          |
   |              |          |
   |              v          v
   |           value -1   set _mode -1
   v              |
set 1 failed   value -1   set -1 success

can that be regard as data race? Or is it possible?

Best regards
-- 
Ma Shimiao
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]