A Fair, Cancelable Semaphore in Go
healeycodes.com·6d·
🔗Concurrency Primitives
Preview
Report Post

They say that you don’t fully understand something unless you can build it from scratch. To wit, my challenge to the more technical readers of this blog is: can you build a semaphore from scratch in your favorite programming language? Bonus points for also handling context cancellation.

I attempted this in Go and it was about 5x harder than I thought it would be. Largely due to concurrency/locking bugs – I assume you’ll have an easier time in, say, JavaScript.

A brief reminder: semaphores are tools used in programming to limit how many tasks can run at the same time by controlling access to shared resources.

Here’s a quick example of their use-case. Your operating system has limits on the amount of file descriptors that can be open but you didn’t know this when you wrote the follo…

Similar Posts

Loading similar posts...