04-09-2019 01:31 PM
@billko wrote:
A little caveat about this is if the code is poorly written - which is likely, given the problem being solved - making a subVI from existing code may force dataflow, eliminating a race condition that needed to be there. My code, which usually consists of many simple modules - isn't very susceptible to this, but with huge, sprawling code, it could be a significant worry.
A very good point. I've been bit by this too, and it's exactly why I setup the source code control before I make any changes.
04-09-2019 02:47 PM
Yup to both. First, establish source control. And then stay alert to billko's caveat about race conditions. Bad code sometimes depends on them.
My most recent time bitten: updating a test system with bad sprawl-like code running on an old latop with a low-cost USB DAQ device. We updated to a new desktop PC with a better PCIe DAQ board. And we immediately started getting fatal buffer overflow errors.
Huh? A faster PC and faster DAQ device & bus connection is having a *harder* time keeping up with buffered DAQ? How does that make sense?
Well, it doesn't. But it was the wrong question. Once I dug up the source code for the application, I found a very special kind of race condition. The first DAQ buffer read was setup to happen at just about the moment the buffer was due to be full. However, because the old USB device was a bit slow at getting configured and started, the code arrived at the buffer read just barely before it overflowed. The new desktop board was enough faster at getting configured and started that the code now arrived at the buffer read just barely *after* it overflowed.
This is different from the typical race conditions we talk about here (usually caused by writing to shared local/global data from multiple places -- and the code in question had plenty of those as well), but it illustrates how bad code can contain surprising dependencies and side effects. Navigating it can feel like having to walk barefoot through a cow pasture at night.
-Kevin P