Even if two threads are writing to the same word, as long as thread 1 doesn't
modify thread_2_data, it should be ok, right?
From: David Chapman [mailto:[email protected]]
Sent: Friday, March 22, 2013 3:31 PM
To: Will Deng
Cc: [email protected]
Subject: Re: [Valgrind-users] Helgrind doesn't handle bit field correctly
On 3/22/2013 2:54 PM, Will Deng wrote:
In our application, we use bit fields a lot. For example:
class data {
unsigned int the_thread_1_data:1;
unsigned int the_thread_2_data:3;
...
};
When one thread is writing to the_thread_1_data, and another thread is reading
or writing to the_thread_2_data, helgrind will flag racing condition. Is this a
known issue in helgrind? Is there a way to get around this? I believe the
operation is multithread safe.
Not safe. Bit fields are generally packed within the same word in memory, so
you now have two threads trying to write the same word without a mutex.
Try an experiment: remove the field widths, so that each integer will be in a
separate memory word. Helgrind should no longer report an error.
--
David Chapman [email protected]<mailto:[email protected]>
Chapman Consulting -- San Jose, CA
Software Development Done Right.
www.chapman-consulting-sj.com<http://www.chapman-consulting-sj.com>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users