Open tedsta opened 4 months ago
What would be the purpose of a thread-local async semaphore?
One example use-case: building block for thread-local multi-producer multi-consumer async channel.
edit - a more concrete use-case: imagine that you are using a non-work-stealing executor and spawn a task to handle each incoming request, and you want to limit the number of active concurrent tasks while still allowing for a backlog of requests before you start dropping requests.
That said, no hard feelings if it doesn't fit in this crate. I can toss it in a new local-semaphore
crate and credit this crate.
Alright, I can see how that could be useful. I suppose I could probably get that in. I'm not sure I have lots of time at the moment, so you might have to wait a bit. If you could implement it yourself and submit a PR, I could review that sooner.
P.S. thanks for your interest in this crate—I'm surprised it has any users at all. I mostly made it for my own use.
Sweet, I'll try to get you a PR in the next couple days.
I was going to write a local semaphore using the pin-list
crate, then thought "surely someone has done this already". Looked at dependents of pin-list
, and here we are :smile:
Hi there - first off, thanks for this crate!
I found the
Semaphore
in this crate is ~35% faster on my x86 laptop in a ping-pong test if I swap theMutex
for anUnsafeCell
to make it a thread-local semaphore.Would you be open to a pull request adding a
LocalSemaphore
and some benchmarks comparing different async semaphores?To avoid code duplication, I can try using the
lock_api
with an internal-onlyNoopMutex
likefutures-intrusive
does. Let me know what you think.