Adagio
Well-known member
- Joined
- Dec 12, 2005
- Messages
- 162
- Programming Experience
- Beginner
I have done several threading tests today, and so far it seems like setting priorities on threads is of no use
In short: I have a sub like this to start several threads (6 in total)
public sub StartThreads()
t1 = New Thread(AddressOf oSquare1.CalcSquare)
t1.Priority = ThreadPriority.Highest
t2 = New Thread(AddressOf oSquare2.CalcSquare)
t2.Priority = ThreadPriority.Lowest
t1.Start()
t2.Start()
End sub
The CalcSquare sub does a lot of useless calculations and now and then updates (through delegates) a progress bar on the form
What I have noticed so far:
- A thread will be between 90 and 100% done before the next thread starts (usually 100%), no matter how much I order it to calculate
- There's a 90% chance that the first thread started will be done first, completely ignoring priority
Here are some result from the last test I made:
Finished - Priority - Thread #
1st - Below normal - 1
2nd - highest - 2
3rd - normal - 3
4th - normal - 6
5th - above normal - 5
6th - highest - 4
Each calculation takes 12 seconds
If the above had just been a random coincidence it would have been ok, but the above test shows pretty much what I have been getting all the time. Or actually it usually is worse, this was one of the rare times where I saw "highest" be among the first two finished
Why is the set priority completely ignored?
In short: I have a sub like this to start several threads (6 in total)
public sub StartThreads()
t1 = New Thread(AddressOf oSquare1.CalcSquare)
t1.Priority = ThreadPriority.Highest
t2 = New Thread(AddressOf oSquare2.CalcSquare)
t2.Priority = ThreadPriority.Lowest
t1.Start()
t2.Start()
End sub
The CalcSquare sub does a lot of useless calculations and now and then updates (through delegates) a progress bar on the form
What I have noticed so far:
- A thread will be between 90 and 100% done before the next thread starts (usually 100%), no matter how much I order it to calculate
- There's a 90% chance that the first thread started will be done first, completely ignoring priority
Here are some result from the last test I made:
Finished - Priority - Thread #
1st - Below normal - 1
2nd - highest - 2
3rd - normal - 3
4th - normal - 6
5th - above normal - 5
6th - highest - 4
Each calculation takes 12 seconds
If the above had just been a random coincidence it would have been ok, but the above test shows pretty much what I have been getting all the time. Or actually it usually is worse, this was one of the rare times where I saw "highest" be among the first two finished
Why is the set priority completely ignored?