Mutex: https://doc.rust-lang.org/std/sync/struct.Mutex.html … Make a channel of capacity 1 that contains the initial value. To lock, call recv() and receive the value. To unlock, call send(value) to put the value back. 2/5
-
-
Show this thread
-
Semaphore: https://docs.rs/std-semaphore/0.1.0/std_semaphore/struct.Semaphore.html … Make a channel of capacity N that is initially empty. To acquire the semaphore, call send(()). To release the semaphore, call recv(). 3/5
Show this thread -
Wait group: https://golang.org/pkg/sync/#WaitGroup … Make a channel of any capacity that is initially empty. To add an item, make a clone of Sender. To remove an item, drop a Sender. To wait until the wait group is empty, call recv(). 4/5
Show this thread -
Parker: https://doc.rust-lang.org/std/thread/fn.park.html … Make a channel of capacity 1 that is initially empty. To park the current thread, call recv(). To unpark a thread, call try_send(()). 5/5
Show this thread
End of conversation
New conversation -
-
-
(not trolling) what do you mean by channel in this context? (also couldn't find context from searching around your tweets)
-
I mean a concurrent queue that can be accessed by multiple threads and closed (or "disconnected"). Examples: https://tour.golang.org/concurrency/2 https://doc.rust-lang.org/std/sync/mpsc/ https://docs.rs/crossbeam-channel/0.4.2/crossbeam_channel/ …
End of conversation
New conversation -
-
-
What's the best generic channel system for Rust?
-
If you want channels that can do almost anything, hen crossbeam-channel. If you want a simpler channel implementation, then flume. If you want async channels, I'll tweet about it in a few days ;)
- 1 more reply
New conversation -
-
-
Is it possible to implement a reentrant lock with a channel?
-
Have a channel with a thread-local variable and counter. When locking, check if the value is stored thread-locally. If so, bump the counter for the number of active locks. When unlocking, decrement the counter. If it drops to zero, move the thread-local value into the channel.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.