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


Groups > comp.programming.threads > #807

Re: Is volatile so bad?

From Alexander Terekhov <terekhov@web.de>
Newsgroups comp.programming.threads
Subject Re: Is volatile so bad?
Date 2012-01-02 15:49 +0100
Organization A noiseless patient Spider
Message-ID <4F01C405.C964D503@web.de> (permalink)
References <2012010123141758633-madler@alumnicaltechedu>

Show all headers | View raw


Mark Adler wrote:
> 
> My parallel gzip, pigz (http://zlib.net/pigz/) is written in C, uses
> pthreads, and everything seems to work fine.  Until recently the word
> "volatile" did not appear in the code.
> 
> However I got an email from a user about a global variable (local to a
> single source file) that he said needed to be volatile.  The variable
> is a pointer to the head of a linked list of jobs, and access to it is
> locked by a related pthreads mutex.  The user said:
> 
> "Without volatile the HP C compiler is doing a prefetch on this
> variable before possess/enter_mutex and uses the prefetched old value
> from a processor register still after the mutex."
> 
> ("possess" is the name of a routine that calls pthread_mutex_lock.)
> 
> So I figured what the heck, it can't hurt too much so I put the
> volatile in there.  The intent is that pigz be portable over a wide
> range of operating systems, so I generally try to accommodate requests
> like this.

If your program is data-race-free then just file a bug report against HP
C (it is really hard to believe that HP C can't deal with locking
correctly).

For use of volatile, see also:

http://www.hpl.hp.com/personal/Hans_Boehm/c++mm/user-faq.html

regards,
alexander.

Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is volatile so bad? Mark Adler <madler@alumni.caltech.edu> - 2012-01-01 23:14 -0800
  Re: Is volatile so bad? Alexander Terekhov <terekhov@web.de> - 2012-01-02 15:49 +0100
    Re: Is volatile so bad? "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-01-03 00:50 +0100
      Re: Is volatile so bad? Mark Adler <madler@alumni.caltech.edu> - 2012-01-05 20:52 -0800
        Re: Is volatile so bad? "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-01-07 23:38 +0100
          Re: Is volatile so bad? Mark Adler <madler@alumni.caltech.edu> - 2012-01-08 14:14 -0800
  Re: Is volatile so bad? Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-06 11:30 +0000
    Re: Is volatile so bad? Mark Adler <google@madler.net> - 2012-01-06 07:33 -0800
      Re: Is volatile so bad? Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-06 22:05 +0000
        Re: Is volatile so bad? Mark Adler <madler@alumni.caltech.edu> - 2012-01-06 19:13 -0800
          Re: Is volatile so bad? Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-07 08:51 +0000

csiph-web