Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Data Race problem

Reply
Thread Tools

Data Race problem

 
 
Gerald Breuer
Guest
Posts: n/a
 
      12-13-2012
Make an atomic increment; then you can forget the whole locking ^^:

static std::atomic<int> aiVar;

void incr()
{
aiVar.fetch_add( 1 );
}

int main()
{
aiVar.fetch_add( 1 );

return 0;
}
 
Reply With Quote
 
 
 
 
Gerald Breuer
Guest
Posts: n/a
 
      12-13-2012
Am 13.12.2012 15:44, schrieb Gerald Breuer:

> Make an atomic increment; then you can forget the whole locking ^^:
>
> static std::atomic<int> aiVar;
>
> void incr()
> {
> aiVar.fetch_add( 1 );
> }
>
> int main()
> {

std::thread thrIncr( incr );

> aiVar.fetch_add( 1 );
>
> return 0;
> }


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question whether a problem with race conditions exists in this case Saxo Java 37 12-19-2011 01:33 PM
How to prevent from race conditions to share data between many process and thread in python mars Python 6 02-07-2007 08:52 AM
VHDL - processes, race conditions, & Verilog Taras_96 VHDL 7 04-05-2005 01:01 AM
race conditions/pulse width The Weiss Family VHDL 6 10-19-2004 02:47 PM
Mega Pixel race is like the Mhz Race Hugo Drax Digital Photography 7 01-12-2004 11:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57