0

I have found a race condition in my application code and now I am wondering how I could create a test case for it, that can be run as a test script that is determined to trigger a specific effect of the race condition and doesn't require a reproduction code patch and/or a manual gdb session.

The situation is a schoolbook example of a race condition: I have an address A and thread 1 wants to write to its location and thread 2 wants to read from it.

So I was thinking of writing a gdb script for this that breaks when thread 1 is about to write at address A then write some garbage into A, then have all threads continue except for thread 1. Then fire the query that causes thread 2 to guarantee to read the garbage at A and then causes a segmentation fault or something.

I guess this is the reverse of set scheduler-locking = on. I was hoping there exist a way to do something like this in a gdb script. But I am afraid there isn't. Hopefully somebody can prove me wrong.

Also I am open to a non-gdb based solution. The main point is that this race condition test, can run automatically without requiring source code modifications. Think of it as an integration test.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Yunus King
  • 1,141
  • 1
  • 11
  • 23

0 Answers0