apply changes from #4 to utils.h#12
Conversation
|
Good point. I think I'll have the thread yield in case of contention then. Also, while we're at it, you should use |
If a platform does not support bus yielding, yield the threads' cpu timeslice early.
|
Okay so on any platform where explicit bus yielding support is unavailable, we call The only minus to this is that in cases of contention this is effectively going to be at least two context-switches long, if not longer. One possible solution might be to just switch to using pthread locks entirely, especially considering that on normal, reasonably updated linux systems, glibc (the default libc) is already pretty ingenious with locks: Simplified Pseudocode: some_lock () {
...
int x = 0;
while (CANNOT_LOCK) {
if (x < a_few_times) {
bus_yield ();
spin ();
} else {
yield_to_kernel ();
}
}
set (lock);
return;
}This makes it decently fast for most purposes and allows the kernel to time switch some threads if a lock is held for a while so that other threads can make progress. |
|
@vmg anyways, that's more of a long term thing that needs benchmarking and such; for right now, I think it's ready to merge. |
|
Thanks for the PR. :) |
and I even signed the CLA this time!