My favorite thing about channels is how they're a universal synchronization primitive. A channel is not just a channel, but also: - a mutex - a semaphore - a wait group - a parker - and a lot more... 1/5
-
Show this thread
-
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
2 replies 0 retweets 12 likesShow 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
1 reply 0 retweets 10 likesShow 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
1 reply 0 retweets 13 likesShow 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
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.