Fix error type check in InternalSetThreadPriority (#16959)
The pthread_setschedparam returns error code as a return value and not
in the errno as the existing code supposes. I have found it when a test
in the lab has failed to set the priority and asserted in this code, but
reported errno as 0.
Also fix the flaky DuplicateHandle test7 that was failing rarely due to the
fact that the secondary thread it has created didn't wait until the main thread
finished fiddling with the priority of that thread.