All Projects → go-pkgz → syncs

go-pkgz / syncs

Licence: MIT License
Concurrency and synchronization primitives

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to syncs

Concurrent
Functional Concurrency Primitives
Stars: ✭ 206 (+154.32%)
Mutual labels:  synchronization, concurrency
Crossbeam
Tools for concurrent programming in Rust
Stars: ✭ 4,180 (+5060.49%)
Mutual labels:  synchronization, concurrency
Linux-Kernel-Driver-Programming
Implementation of PCI drivers, kprobe, sysfs, devfs, sensor driver, miscdevices, synchronization
Stars: ✭ 43 (-46.91%)
Mutual labels:  synchronization, concurrency
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+113.58%)
Mutual labels:  synchronization, concurrency
linked-blocking-multi-queue
A concurrent collection that extends the existing Java concurrent collection library, offering an optionally-bounded blocking "multi-queue" based on linked nodes.
Stars: ✭ 41 (-49.38%)
Mutual labels:  synchronization, concurrency
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+28.4%)
Mutual labels:  synchronization, concurrency
TAOMP
《多处理器编程的艺术》一书中的示例代码实现,带有注释与单元测试
Stars: ✭ 39 (-51.85%)
Mutual labels:  synchronization, concurrency
Corium
Corium is a modern scripting language which combines simple, safe and efficient programming.
Stars: ✭ 18 (-77.78%)
Mutual labels:  concurrency
JTK
JTK is a library designed for writing applications and libraries in C. It provides core utilities such as collections, unit testing, I/O streams, threads and much more.
Stars: ✭ 25 (-69.14%)
Mutual labels:  concurrency
psched
Priority-based Task Scheduling for Modern C++
Stars: ✭ 59 (-27.16%)
Mutual labels:  concurrency
CareKitSample-ParseCareKit
An example application of CareKit's OCKSample synchronizing iOS and watchOS to the cloud via ParseCareKit and parse-hipaa
Stars: ✭ 18 (-77.78%)
Mutual labels:  synchronization
pyftpsync
Synchronize directories using FTP(S), SFTP, or file system access.
Stars: ✭ 85 (+4.94%)
Mutual labels:  synchronization
gpool
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.
Stars: ✭ 84 (+3.7%)
Mutual labels:  concurrency
go-stm
Software Transactional Memory for Go
Stars: ✭ 15 (-81.48%)
Mutual labels:  concurrency
chicken-gochan
Go-like Channels for Chicken Scheme
Stars: ✭ 18 (-77.78%)
Mutual labels:  concurrency
dbsync
Small library for sync android SqlLite database to cloud storage (for now only GDrive)
Stars: ✭ 30 (-62.96%)
Mutual labels:  synchronization
swoole-futures
⏳ Futures, Streams & Async/Await for PHP's Swoole asynchronous run-time.
Stars: ✭ 100 (+23.46%)
Mutual labels:  concurrency
drone-cortexm
ARM® Cortex®-M platform crate for Drone, an Embedded Operating System.
Stars: ✭ 31 (-61.73%)
Mutual labels:  concurrency
state
A Redux-based state container for local-first software, offering seamless synchronization using Automerge CRDTs. (Formerly known as 🐟 Cevitxe).
Stars: ✭ 126 (+55.56%)
Mutual labels:  synchronization
geeteventbus
An inprocess eventbus for highly concurrent Python applications
Stars: ✭ 17 (-79.01%)
Mutual labels:  concurrency

Syncs - additional synchronization primitives

Build Status Go Report Card Coverage Status

Package syncs provides additional synchronization primitives.

Install and update

go get -u github.com/go-pkgz/syncs

Details

Semaphore

Implements sync.Locker interface but for given capacity, thread safe. Lock increases count and Unlock - decreases. Unlock on 0 count will be blocked.

    sema := syncs.NewSemaphore(10) // make semaphore with 10 initial capacity
    for i :=0; i<10; i++ {
        sema.Lock() // all 10 locks will pass, i.w. won't lock
    }
    sema.Lock() // this is 11 - will lock for real

    // in some other place/goroutine
    sema.Unlock() // decrease semaphore counter

SizedGroup

Mix semaphore and WaitGroup to provide sized waiting group. The result is a wait group allowing limited number of goroutine to run in parallel.

By default, the locking happens inside of goroutine, i.e. every call will be non-blocked, but some goroutines may wait if semaphore locked. It means - technically it doesn't limit number of goroutines, but rather number of running (active) goroutines. In order to block goroutines from even starting use Preemptive option (see below).

    swg := syncs.NewSizedGroup(5) // wait group with max size=5
     for i :=0; i<10; i++ {
        swg.Go(fn func(ctx context.Context){
            doThings(ctx) // only 5 of these will run in parallel
        })
    }
    swg.Wait()

ErrSizedGroup

Sized error group is a SizedGroup with error control. Works the same as errgrp.Group, i.e. returns first error. Can work as regular errgrp.Group or with early termination. Thread safe.

Supports both in-goroutine-wait via NewErrSizedGroup as well as outside of goroutine wait with Preemptive option. Another options are TermOnErr which will skip (won't start) all other goroutines if any error returned, and Context for early termination/timeouts.

Important! With Preemptive Go call can block. In case if maximum size reached the call will wait till number of running goroutines dropped under max. This way we not only limiting number of running goroutines but also number of waiting goroutines.

    ewg := syncs.NewErrSizedGroup(5, syncs.Preemptive) // error wait group with max size=5, don't try to start more if any error happened
     for i :=0; i<10; i++ {
        ewg.Go(fn func(ctx context.Context) error { // Go here could be blocked if trying to run >5 at the same time 
           err := doThings(ctx)     // only 5 of these will run in parallel
           return err
        })
    }
    err := ewg.Wait()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].