Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #1041

Re: Who needs acquire semantics for read operations?

Date 2012-09-01 19:24 +0200
From Marcel Müller <news.5.maazl@spamgourmet.org>
Newsgroups comp.programming.threads
Subject Re: Who needs acquire semantics for read operations?
References <f5a18d06-5413-4bef-93f9-96686cd08bb9@k20g2000vbk.googlegroups.com>
Message-ID <504244da$0$6576$9b4e6d93@newsspool3.arcor-online.net> (permalink)
Organization Arcor

Show all headers | View raw


On 01.09.12 10.28, Rani Sharoni wrote:
> AFAIU, acquire semantics for read operations is guaranteed for
> volatile variables by the MSVC compiler.

AFAIK x86/x64 has no memory reordering anyway. VC can only compile for 
x86/x64. So volatile is mostly useless. Is mainly disables the optimizer.

> Can you think about any situation in which such guarantee on non-read-
> modify operation is useful?

Yes.

A common patter is to have a state variable with a forward only state 
graph. Reading a state that is a final value in this graph is known to 
be thread-safe with acquire semantics only. Example: an object might be 
loaded asynchronously. The finished flag is final. If you check for 
finished with acquire semantics you do not need any locking unless you 
get the value "not finished". You can combine this with a conditional 
variable and the double check idiom.

> All the locks/try-locks I know of (e.g. mutex) have acquire semantics
> but they also require read-modify operation in order to acquire the
> lock in the first place…

If you are writing too, you usually need a full membar.


Marcel

Back to comp.programming.threads | Previous | NextNext in thread | Find similar


Thread

Re: Who needs acquire semantics for read operations? Marcel Müller <news.5.maazl@spamgourmet.org> - 2012-09-01 19:24 +0200
  Re: Who needs acquire semantics for read operations? Rani Sharoni <ranisharoni75@gmail.com> - 2012-09-02 00:10 -0700
    Re: Who needs acquire semantics for read operations? Marcel Müller <news.5.maazl@spamgourmet.org> - 2012-09-02 10:13 +0200
  Re: Who needs acquire semantics for read operations? Václav Zeman <v.haisman@sh.cvut.cz> - 2012-09-04 04:31 -0700
    Re: Who needs acquire semantics for read operations? Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-09-04 15:24 +0200
      Re: Who needs acquire semantics for read operations? Rani Sharoni <ranisharoni75@gmail.com> - 2012-09-04 23:41 -0700
  Re: Who needs acquire semantics for read operations? Toby Douglass <a@b.com> - 2012-09-10 09:41 +0200

csiph-web