Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #103894
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Memory not updating in thread as expected |
| Date | 2017-02-14 17:26 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <874lzwsmxy.fsf@bsb.me.uk> (permalink) |
| References | (5 earlier) <o7ufui$upl$1@dont-email.me> <87lgt9rpww.fsf@bsb.me.uk> <87r330259r.fsf@universite-de-strasbourg.fr.invalid> <87a89oss2h.fsf@bsb.me.uk> <87mvdo1zha.fsf@universite-de-strasbourg.fr.invalid> |
Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> writes:
>>
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> <snip>
>>>> [1] In fact, I think that asking when, and on what systems, can you
>>>> use 'if' like that with a condition variable would make a good
>>>> interview question!
>>>
>>> How nasty :-) I would say: use a loop unless you have exactly two
>>> threads that interact/synchronize exactly once.
>>
>> And then only if you know the CVs your are using a free from spurious
>> wake-ups -- a wait finishing when no thread has signalled the
>> condition. That is sometimes done to make the implementation
>> efficient. I've not checked if C makes this guarantee. I think POSIX
>> does not.
>
> You're right.
>
> Actually C11 (as of N1570) does not mention the problem, but Defect
> Report 480 (available at
> http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm) implies
> that spurious wakeups can happen.
>
> POSIX (as found at http://pubs.opengroup.org/onlinepubs/9699919799/)
> mentions "These functions shall not return an error code of [EINTR]."
> but this does not apply to spurious wakeups, which are explicitly
> mentioned ("Spurious wakeups from the pthread_cond_timedwait() or
> pthread_cond_wait() functions may occur."). The informative sections
> add: "It is thus recommended that a condition wait be enclosed in the
> equivalent of a "while loop" that checks the predicate."
Thanks for that. I now feel a little lazy since I should probably have
done that myself!
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 12:46 +0200
Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 05:18 -0800
Re: Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 16:25 +0200
Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 10:30 -0800
Re: Memory not updating in thread as expected Jerry Stuckle <jstucklex@attglobal.net> - 2017-02-13 14:30 -0500
Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 05:46 -0800
Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-13 14:30 +0000
Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-13 15:13 -0800
Re: Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 16:36 +0200
Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-13 23:15 +0100
Re: Memory not updating in thread as expected James Kuyper <jameskuyper@verizon.net> - 2017-02-13 22:04 -0500
Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-14 09:44 +0100
Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 11:07 +0000
Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-14 12:46 +0100
Re: Memory not updating in thread as expected Robert Wessel <robertwessel2@yahoo.com> - 2017-02-16 05:12 -0600
Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-16 12:44 +0100
Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 15:53 +0100
Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 15:36 +0000
Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 17:58 +0100
Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 17:26 +0000
Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 10:43 +0100
Re: Memory not updating in thread as expected Robert Wessel <robertwessel2@yahoo.com> - 2017-02-14 03:52 -0600
Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 11:36 +0100
Re: Memory not updating in thread as expected supercat@casperkitty.com - 2017-02-14 05:31 -0800
Re: Memory not updating in thread as expected Ken Brody <kenbrody@spamcop.net> - 2017-02-13 12:44 -0500
Re: Memory not updating in thread as expected Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-02-13 10:58 -0700
Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-14 15:13 -0800
Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-14 16:37 -0800
csiph-web