Skip to content

Implementing a custom driver #4180

Answered by Darksonn
farnoy asked this question in Q&A
Oct 19, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Your idea of having a separate thread is a good one. Basically, you would write a custom impl of the Future trait that asks your dedicated thread to add the semaphore to its list of semaphores, also informing the thread which waker it should wake when the semaphore gets a permit. There is an example of waking a future from another thread here.

As for noticing new additions to the set of semaphores, why not make a semaphore for that? Every time you've added a new waker, you add a permit on a special semaphore, which wakes up your thread. The thread can then check for new semaphores and go back to sleep.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@farnoy
Comment options

@Darksonn
Comment options

Answer selected by farnoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants