By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Threading: Thread takes dominance, & the rest wait until it's finnished.

DTeCH
P: 23
Hello guys,


I have a problem... I've seen it a few times before, but have never gotten an answer when I asked online.


My problem is, when ever I make a multi-threaded program for downloading files from usenet, ONE thread would take authority over all the rest, even though it was created with the same priority as all the rest, & is an instance of the same class, yet it's not the first thread, nor the last, but somewhere in between.

For visual aid, imagine 10 progress bars, each individually doing their thing... all is well, & working flawlessly, but once in a while, one thread would cruise from 1% to 100% done - while all the rest hang at whatever their percentage was when this rogue thread started at 0%, & does not move until the rogue thread hits 100%, & is getting another bit of work from the download queue.

At this point, all the other threads flow together updating their progress value all at once as expected until the rogue begins downloading again. All other threads does a little work until the rogue starts at 0% again. All others freezes until rogue gets to 100%, & is grabbing a bit of work from the queue again. The time that the other threads gets to run together is about 1 second... while the rogue is getting another bit of work from the queue, but when it begins it's work, nothing else can run until it hits 100%, & is getting more from the queue.


As far as code is concerned, it's the usual multi-instance class that does the exact same thing per instance, except each instance is updating to separate progress bars.

Program is started, & based on user's previous choice, reads the amount the user last chose, & begins creating the threads in a simple loop, & exits when the number is reached.

The threads are now active, & can be seen when each thread shows 0% because the user has not chosen anything to download yet.

Each thread has the same priority, & nothing is special about any of them... they are all the same, & identical in operation, yet one goes haywire sometimes.

I will post a video link soon to show this behavior.

This thread remains rogue until the program is restarted, no matter how many things is downloaded, or how long it runs. Any one of the other threads becomes rogue at program start up, but sometimes, all is well also... with everything running fine as expected.

This is really bugging me nowadays because i cannot see what is causing it. It's a simple thread creation loop, & all is identical... so why does one thread (random thread... any "one" from 1st created, to last created) becomes rogue?

Is it possible that there's a threading bug in the .NET Framework?


ps: I have seen this behavior in other programs as well... not just my own.
Aug 23 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.