Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #807
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Alexander Terekhov <terekhov@web.de> |
| Newsgroups | comp.programming.threads |
| Subject | Re: Is volatile so bad? |
| Date | Mon, 02 Jan 2012 15:49:41 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 33 |
| Message-ID | <4F01C405.C964D503@web.de> (permalink) |
| References | <2012010123141758633-madler@alumnicaltechedu> |
| Reply-To | terekhov@web.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| Injection-Info | mx04.eternal-september.org; posting-host="MCbSEzW5qwGLFMNXJh39IQ"; logging-data="24163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CEOC/voWmThbXsRQz2Xw9LG7R9kMnJZc=" |
| X-Mailer | Mozilla 4.77 [en] (Windows NT 5.0; U) |
| X-Accept-Language | en |
| Cancel-Lock | sha1:Do2aS/FW1Jq9LZxI8gAPqUMopuU= |
| Xref | x330-a1.tempe.blueboxinc.net comp.programming.threads:807 |
Show key headers only | 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
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