-
-
Notifications
You must be signed in to change notification settings - Fork 426
fix Issue 8960 - Unable to set thread priority #550
Conversation
MartinNowak
commented
Jul 24, 2013
- ignore FreeBSD error when get-/setting priority on terminated thread
- this also ignores invalid thread handles
Note, that situation on linux and windows has fundamentally the same problem. Would you place some code between starting some quickly terminated thread and setting/getting its priority, you would see same error on these platforms. Also ESRCH does not distinguish between outlived thread IDs and simply wrong ones, so passing any wrong value in FreeBSD will be silently ignored. |
We can't make setting/getting the priority of a thread an error without providing a way to synchronize that operation with the thread lifetime. The other problem is that access to m_isRunning is not synchronized so we're missing a way to determine whether a thread has terminated. |
Testing for whether a thread is running does have some potential slippage, but not much. Accesses to m_isRunning should probably be made atomic(msync.raw) at least just to make things more clear. |
Essentially any use of a state variable in a conditional before taking some action is buggy unless both the conditional and the action are both done while a single lock is held throughout both operations. Just making the conditional check atomic is insufficient (unless it's one way, like isShutdown or similar conditions). I totally agree that the conditional on freebsd part is fundamentally wrong. It's all platforms. |
I wouldn't make setting priority on a non-running thread an error because I'm inclined to say that you should be able to create a thread object, set its priority, and then start the thread. And now that I look at the code, it doesn't support this behavior. Either way though, I don't see a point in trying to enforce that this call is only valid for running threads. |
Well glibc and OSX's libc will simply set/get the priority on the dead thread.
We'd need to save the priority in the Thread object.
Setting the priority before creation (in the pthread_attr_t) has no effect on FreeBSD. We tried that with #542. |
I'm inclined to agree with Sean. You should be able to create a thread, set its priority, start it, and have that priority take effect when it's started. If that means checking the priority in |
So, what are we going to do with this issue? I added a really fast mac to the build cluster some this weekend (can't stay full time). It failed something in the neighborhood of 1/4 of the test runs due to this bug. |
I don't know enough about this issue to be able to pull this. |
Let's close it for now, people didn't like the idead of ignoring an error. |
Reopened. |
Implementation is now based on |
ping |
ping |
Updated |
Failing on Darwin/32 with "Unable to set priority". :-( |
- Ignore error when get-/setting the priority of a terminated thread.
9d552e2
to
62696b4
Compare
OK updated again. |
Looks clean now. Time to merge? |
LGTM |
Auto-merge toggled on |
fix Issue 8960 - Unable to set thread priority