It nearly doesn't matter in terms of numbers of context switches if
you signal a condvar from inside our outside. The above program run
on a Zen4-CPU with WSL2:
inside: 20130
outside: 19811
On a 28 core Skylake-CPU with Ubuntu:
inside: 19997
outside: 19888
There is a scalability problem wrt signalling inside the critical
section. Does your convdar impl use wait morphing?
Am 12.04.2025 um 21:33 schrieb Chris M. Thomasson:
There is a scalability problem wrt signalling inside the critical
section. Does your convdar impl use wait morphing?
There's no scalability problem with that since the kernel call to
release a thread happens only when the mutex is accessible *and*
the cv is signalled.
On 4/13/2025 8:38 AM, Bonita Montero wrote:
Am 12.04.2025 um 21:33 schrieb Chris M. Thomasson:
There is a scalability problem wrt signalling inside the critical
section. Does your convdar impl use wait morphing?
There's no scalability problem with that since the kernel call to
release a thread happens only when the mutex is accessible *and*
the cv is signalled.
No. ...
When you signal a condvar while holding the lock it means that waiters can wake and just instantly wait on the lock. This is why wait
morphing was created. It helps, but only so much...
Am 13.04.2025 um 21:32 schrieb Chris M. Thomasson:
On 4/13/2025 8:38 AM, Bonita Montero wrote:
Am 12.04.2025 um 21:33 schrieb Chris M. Thomasson:
There is a scalability problem wrt signalling inside the critical
section. Does your convdar impl use wait morphing?
There's no scalability problem with that since the kernel call to
release a thread happens only when the mutex is accessible *and*
the cv is signalled.
No. ...
The numer of context-switches my code shows say that there's only
one context-switchz per wait.
When you signal a condvar while holding the lock it means that
waiters can wake and just instantly wait on the lock. This is why wait
morphing was created. It helps, but only so much...
idiot.
You code is hard to read. ...
Signalling while locked or unlocked was an old debate. Think of signalling while holding the lock. A thread gets woken and immediately sees that the lock is held. Oh well. Wait morphing can help with that. However, signal outside when you can...
Am 13.04.2025 um 23:40 schrieb Chris M. Thomasson:
You code is hard to read. ...
The code is beautiful.
Signalling while locked or unlocked was an old debate. Think of
signalling
while holding the lock. A thread gets woken and immediately sees that the
lock is held. Oh well. Wait morphing can help with that. However, signal >> outside when you can...
The number of context-switches determined via getrusage() is twice per
loop iteration, i.e. on switch to the thread and one switch from the
thread; so everything is optimal with glibc.
In real applications there is generally more going on in those critical sections vs your test... Well, I have seen some horror shows in my life.
Again, think of a scenario where the lock is held. The thread signals... Another thread wakes up and has to instantly block on a wait morphing
queue in the kernel.
Am 15.04.2025 um 21:07 schrieb Chris M. Thomasson:
In real applications there is generally more going on in those
critical sections vs your test... Well, I have seen some horror shows
in my life.
Again, think of a scenario where the lock is held. The thread
signals... Another thread wakes up and has to instantly block on a
wait morphing queue in the kernel.
Not with glibc.
Sigh. I would need to see how glibc works internally. But that is
besides the point. Try to signal/broadcast outside when possible.
Am 17.04.2025 um 00:59 schrieb Chris M. Thomasson:
Sigh. I would need to see how glibc works internally. But that is
besides the point. Try to signal/broadcast outside when possible.
As I've shown that's not necessary with glibc; the number of context
switches and the CPU time is nearly the same for both cases.
So, signal wherever you like! I don't care. I will signal outside when I can. That's that.
Am 17.04.2025 um 07:26 schrieb Chris M. Thomasson:
So, signal wherever you like! I don't care. I will signal outside when
I can. That's that.
Of course you can, but it doesn't matter if you signal from outside or inside.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,029 |
Nodes: | 10 (1 / 9) |
Uptime: | 182:40:48 |
Calls: | 13,337 |
Calls today: | 4 |
Files: | 186,574 |
D/L today: |
5,560 files (1,540M bytes) |
Messages: | 3,356,614 |