-2

I am aware about the risks on race conditions and that values written or read might be corrupted. I am in a situation where I have races on boolean and integers and a couple of classes instance.

Could this lead to a program crash, or any other nasty effect on my program aside from the data not being valid? Do I have worry for the worst?

I have 2 versions of my program a debug and another with a lot of options for optimization. I am worried about this last one as it goes to production.

user229044
  • 232,980
  • 40
  • 330
  • 338
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173

2 Answers2

3

data not being valid may result in anything (i.e. you invoke undefined behavior). So having that in mind your application may crash, leak memory, format you hard drive and almost anything else.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
  • 1
    Um, "may result in anything" is "undefined behavior". Undefined behavior does **not** mean that something nasty will happen. Just that it could. – Pete Becker Mar 19 '13 at 13:39
  • 1
    +1 "Data" isn't just something loaded from a file. [Here's a good example](http://mailinator.blogspot.co.uk/2009/06/beautiful-race-condition.html) where a race corrupts the internal state of a hashtable, causing infinite loops when accessing it. – anton.burger Mar 19 '13 at 13:40
  • @PeteBecker good point now that I read my statement it does not make much sense. Will refactor it. Thanks. – Ivaylo Strandjev Mar 19 '13 at 13:41
0

Could this lead to a program crash

Depends on the resource being raced for, but yes. If one thread grabs the resource and another thread needs it to progress, you can get undefined behavior and even program crashes.

any other nasty effect on my program aside from the data not being valid?

Aside from invalid data (thus a practically useless program), you could also be prone to deadlocks.

The wikipedia article on race condition is a good place to find answers to questions such as these.

xcdemon05
  • 1,372
  • 5
  • 25
  • 49