Jump to content

Finding Race Conditions


Recommended Posts

Since my job lately has been to debug existing code, I have found several race conditions. Sometimes I can spot these just by looking at the code, but often it's just by happenstance that I find them - usualy by doing things like initializing local variables with some bogus number or by drawing frames around code and throwing in a few delays here and there. IS there a trick to debugging race conditions?

Speaking of (what I call) race conditions, is the attached picture a true race condition? On this VI, the error was occuring every 3rd or 4th entry into the VI.

I fixed the issue by intializing the "Char Offset" to 0. A few moments later I moved the wire as shown and it fixed it, and got rid of the local I added. Since the problem was initially fixed by toying with a Local Variable, I defined this problem as a Race Conditions. Is it?

Any advise for further reading?

THANKS!

Richard

Link to comment

Strictly speaking there is still a possible race condition in your fix since nothing garantees that the char offset terminal is written before entering the loop and reading its local.

The safest way to implement this is to add a shift register in the for loop and feed it with the char offset wire.

http://forums.lavag.org/index.php?act=attach&type=post&id=6148

You can now see that you don't even need a local except for display purposes

Link to comment

QUOTE(BrokenArrow @ Jun 19 2007, 09:32 AM)

The placement of the control and indicator don't follow the left-right top-bottom conventions of the LabVIEW Development Guidelines. The race condition would be more obvious if the conventions were followed.

I had to do a double-take because the indicator was above the control and wired from the right. These sorts of problems can be found with the VI Analyzer Toolkit. I've been using this more and more and like it (although its a bit anal sometimes) I need to make my own configuration at some point.

Link to comment

QUOTE(LV Punk @ Jun 19 2007, 12:06 PM)

Indeed. This is 5.1, which doesn't show the flow direction on terminals and lets you wire from any direction. This inherited code is full of that kind of qurky wiring.

QUOTE(jpdrolet @ Jun 19 2007, 11:06 AM)

The safest way to implement this is to add a shift register in the for loop and feed it with the char offset wire.

Sweet. If I had a dollar for every time this code used a local rather than a shift register, I could buy this website and host porn. Nah, they'd never allow porn on the internet.

QUOTE(Jim Kring @ Jun 19 2007, 10:16 AM)

It is a classic example of a race condition.

Thanks Jim and Ton. Every time I mention "race condition" around here they look at me like I'm making sh!t up. :wacko:

-Richard

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.