This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: thread safety level of fwide
- From: MaShimiao <mashimiao dot fnst at cn dot fujitsu dot com>
- To: Alexandre Oliva <aoliva at redhat dot com>
- Cc: "Carlos O'Donell" <carlos at redhat dot com>, <libc-help at sourceware dot org>, <triegel at redhat dot com>
- Date: Thu, 20 Nov 2014 09:37:38 +0800
- Subject: Re: thread safety level of fwide
- Authentication-results: sourceware.org; auth=none
- References: <546C4388 dot 1090209 at cn dot fujitsu dot com> <or61eborsv dot fsf at free dot home>
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)