Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello,

Thanks for taking the time to read this post. I have been seeing a problem with a Visual Studio 2005 multithreaded user program running at high priority.

I am working on wireless network protocols and one thing the protocol does is monitor link quality. I am testing with perfect links so the link qualities measured should be at or near 100%.

This feature had been working okay till I changed the code to work at much higher link rates. The links used to go at kilobits per second; now they go at 10s and 100s of kilobits per second.

This is the problem:

- Sometimes I see that the thread monitoring link quality fails to work consistently so that the measured link quality goes down when it should be near perfect. This happens on the last protocol stack to start up.

- When I add one or more breakpoints in the thread using Visual Studio 2005, it starts working properly again after a while. I can tell as the breakpoints initially get hit once in a while, then very often, and the link quality measured goes up to acceptable levels. After I disable the breakpoints, the thread seems to keep working okay and the protocol appears to work as it should, even overnight, till I shut it down.

The quad- and oct-core PCs used have low processor utilization and there is ample main memory and disk space to spare. The operating systems used are Windows 7 and XP. All the PC configurations above have exhibited the same problem and I have not tried this on any other configuration.

It would be appreciated greatly if someone could help.

Best,
Jeremy

What I have tried:

At first I had a few network protocol stacks running on the same PC. I suspected the OS had problems supporting so many high priority processes, so I moved one stack to another PC. This worked for a while, but the problem has resurfaced even with the single protocol stack on a PC.
Posted

1 solution

This is as simple as that: if your thread works only with the breakpoints, it does not work at all. The code is simple incorrect. The behavior is a clear indication of the phenomena of incorrect dependency on the time of execution commonly known as "race condition": Race condition — Wikipedia, the free encyclopedia.

Now, as you did not create any code sample we could consider here, I cannot analize it and find out where your code design is wrong, or if it has certain bugs. Also, it could so happen that it's too hard to find an exact reason for race condition, but usually there can be some indirect sings of wrong code, some techniques or even style which may formally result in correct code but are impractiable and error-prone.

So, my advice is: learn threading techniques properly and read the article I referenced to understand how race condition gets you into trouble. Your follow-up questions will be welcome.

—SA
 
Share this answer
 
Comments
Patrice T 15-Feb-16 23:37pm    
+5
Sergey Alexandrovich Kryukov 16-Feb-16 1:00am    
Thank you.
—SA
Member 12329595 16-Feb-16 2:24am    
Thanks Sergey, your reply is quite informative. I appreciate you raising the possibility of posting code here so you can see it; I am afraid it is proprietary in this case and not in my power to decide.

You mentioned formally right code that may be impractical / error-prone: could you help share what some of these are?

Thanks,
Jeremy
Sergey Alexandrovich Kryukov 16-Feb-16 3:38am    
You are welcome. No one will probably even want to look at your proprietary and probably pretty heavy code. This is not how help with code can be got, realistically. Ideally, you have to demonstrate the problem by writing some sample/prototype specially for this purpose and research, making it absolutely minimal, focusing only one one problem. I do understand that it's not always possible to reproduce the problem this way.

By "impractical/error-prone" I meant not the code, but style and some techniques: spaghetti style, something hard to analyze, or potentially dangerous, and so on. I hope I don't write such code, but I face it number of times, and, naturally, don't have anything to show. It's generally would be pretty hard, even given enough time. As I say, it's a matter of learning correct parallel programming; something which is easier to advise than to accomplish.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900