sync
sync copied to clipboard
[mirror] concurrency primitives
This adds a new package, x/sync/singleflight/v2, which is a version of x/sync/singleflight that uses generics instead of `string`, and `interface{}` in its API. The biggest changes are to the `Do`...
This PR is an alternative to the proposal in #9, inspired by @bcmills' [comment](https://github.com/golang/sync/pull/9#issuecomment-572705800). The general idea is to add a second function argument to `Do`, which is guaranteed to...
# Motivation I use semaphore to guard a pool of objects. It other words tokens in the semaphore correspond to my items in the pool. The standard acquire function looks...
SetLimit(10) Go(xx) //start a groutine ,g.done be called if task done SetLimit(-1) //
Semaphores are often used to bound concurrency (e.g worker-pool) and it is sometimes preferred to be able to resize the semaphore/workerpool to bound concurrency dynamically in respond to load. This...
Add a lock named leadlock And a simple single flight based leadlock which should having higher performance than singleflight.Group
A Goroutine without recover protection will panic if something wrong happended, so I add recover to Go(). PTAL, thanks :)
golang.org/x/sync/singleflight: add Use method to perform cleanup of temp resource after last use
### Background: We are using singleflight to run expensive procedure that creates a temporary resource (temp file). Our challenge - we need to determine when it is safe to cleanup...
In Singlelight, the function of mutex is to protect the atomic access of critical resources in the map. In the following optimization, after deleting the key of the map, the...