All Projects → mustafakemalgilor → concurrent-resource

mustafakemalgilor / concurrent-resource

Licence: other
A header-only C++ library that allows easily creating thread-safe, concurrency friendly resources.

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to concurrent-resource

Concurrent Map
a thread-safe concurrent map for go
Stars: ✭ 2,627 (+15352.94%)
Mutual labels:  concurrency, thread-safety
Di
DI: C++14 Dependency Injection Library
Stars: ✭ 756 (+4347.06%)
Mutual labels:  boost, design-patterns
Threadly
A library of tools to assist with safe concurrent java development. Providing unique priority based thread pools, and ways to distrbute threaded work safely.
Stars: ✭ 196 (+1052.94%)
Mutual labels:  concurrency, threading
Important Java Concepts
🚀 Complete Java - A to Z ║ 📚 Notes and Programs of all Important Concepts of Java - OOPS, Data Structures, Algorithms, Design Patterns & Development + Kotlin + Android 🔥
Stars: ✭ 135 (+694.12%)
Mutual labels:  concurrency, design-patterns
thread-pool
BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
Stars: ✭ 1,043 (+6035.29%)
Mutual labels:  concurrency, threading
Pht
A new threading extension for PHP
Stars: ✭ 175 (+929.41%)
Mutual labels:  concurrency, threading
Sml
SML: C++14 State Machine Library
Stars: ✭ 540 (+3076.47%)
Mutual labels:  boost, design-patterns
Transient
A full stack, reactive architecture for general purpose programming. Algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions, multithreading, Web, and distributed computing with complete de-inversion of control (No callbacks, no blocking, pure state)
Stars: ✭ 617 (+3529.41%)
Mutual labels:  concurrency, threading
go-left-right
A faster RWLock primitive in Go, 2-3 times faster than RWMutex. A Go implementation of concurrency control algorithm in paper <Left-Right - A Concurrency Control Technique with Wait-Free Population Oblivious Reads>
Stars: ✭ 42 (+147.06%)
Mutual labels:  concurrency, concurrent-data-structure
Golang Set
A simple set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.
Stars: ✭ 2,168 (+12652.94%)
Mutual labels:  threadsafe, concurrency
Floyd
The Floyd programming language
Stars: ✭ 133 (+682.35%)
Mutual labels:  concurrency, threading
java-multithread
Códigos feitos para o curso de Multithreading com Java, no canal RinaldoDev do YouTube.
Stars: ✭ 24 (+41.18%)
Mutual labels:  concurrency, concurrent-data-structure
Agency
Execution primitives for C++
Stars: ✭ 127 (+647.06%)
Mutual labels:  concurrency, threading
think-async
🌿 Exploring cooperative concurrency primitives in Python
Stars: ✭ 178 (+947.06%)
Mutual labels:  concurrency, threading
Swift Design Patterns
🚀 The ultimate collection of various Software Design Patterns implemented in Swift [Swift 5.0, 28 Patterns].
Stars: ✭ 85 (+400%)
Mutual labels:  concurrency, design-patterns
Kernels
This is a set of simple programs that can be used to explore the features of a parallel platform.
Stars: ✭ 287 (+1588.24%)
Mutual labels:  boost, threading
Concurrencpp
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all
Stars: ✭ 340 (+1900%)
Mutual labels:  concurrency, threading
Javamtp
《Java多线程编程实战指南(设计模式篇)》源码
Stars: ✭ 575 (+3282.35%)
Mutual labels:  concurrency, design-patterns
treap
A thread-safe, persistent Treap (tree + heap) for ordered key-value mapping and priority sorting.
Stars: ✭ 23 (+35.29%)
Mutual labels:  threadsafe, concurrency
lfqueue
lock-free FIFO queue by C native built it, easy built cross platform(no extra dependencies needed) , guarantee thread safety memory management ever!
Stars: ✭ 104 (+511.76%)
Mutual labels:  threadsafe, thread-safety

concurrent-resource

A header-only C++ library that allows easily creating thread-safe, concurrency friendly resources.

Try online

brief

The aim of this library is making it easier to create thread-safe objects without dealing with thread-synchronization primitives. To achieve this, we use encapsulation to restrict access to resource, then grant access again in a controlled manner via accessor pattern.

accessors?

Accessors are simple types, bundled with a reference to shared object, and a lock. The attributes of shared object and lock depends on accessor's type (read,write). As they contain lock object internally, the lock is held during entire life of an accessor object's lifetime.

#include "concurrent_stl.hpp" // or concurrent_boost.hpp
#include <vector>
#include <iostream>

// A very-basic example
int main(void){
  // Wrap a regular vector to make it thread-safe
  mkg::concurrent<std::vector<std::string>> books;
  {
    // Grab a write accessor (we can manipulate the vector through it)
    auto writer = books.write_access_handle();
    // Now, an exclusive lock is held upon the construction of write accessor
    // by std::unique_lock<std::shared_mutex>(...) (or boost::)
    // We can reach the underlying vector by just ->'ing the writer.
    writer->push_back("White Fang");
    writer->push_back("Harry Potter and the Philosopher's Stone");
    // Attention: Do not attempt to acquire another write accessor from same thread whilst
    // another one is already alive.
  }
  // Here, right after the accessor object is destroyed (by going out of scope)
  // the lock is released. 
  {
    // Grab a read accessor (read-only, cannot modify the vector through it)
    auto reader = books.read_access_handle();
    // Treat the accessors as if they're pointers to the underlying resource
    // (or std|boost::optional's if you will)
    for(const auto & book : (*reader)){
      std::cout << book << std::endl;
    }
  }
}

dependencies?

C++20 is required as project now uses concepts.

how to compile?

As this is a header-only library, you do not need to do anything special. Just include concurrent_resource.hpp and you'll be fine. To compile main.cpp, which contains the examples, you need CMake (if you're lazy), or just type

  • C++20(std): g++ main.cpp -lpthread -o example --std=c++2a
  • BOOST : g++ main.cpp -lpthread -lboost_system -lboost_thread -o example --std=c++2a in source folder. (or equivalent in Windows)

anything to worry about?

Well, there is a single pitfall you should consider while using this library.

  • Do not try to grab two accessors from one thread at the same time. The reason for this is, std:: and boost:: shared mutexes are non-reentrant (non-recursive)

pros

  • extremely easy to use
  • thread synchronization primitives are totally abstract from user's perspective
  • read-write rights are enforced through accessors, leading to safer code in many cases
  • raii style lifetime management

cons

  • std::shared_mutex & boost::shared_mutex are not known with their blow-your-socks-off performance (but they'll do just fine ™ ) :shipit:

what is the difference from the first release?

  • Concurrent type is now fully generic, you can now implement your custom Lockable and Lock types and use it with concurrent wrapper
  • Concept validation (via C++20 concepts)
  • Simplifications

future plans

  • well, most of the future plans are now obsolete, because this new release is abstract from any lock implementation.

license

The project is released under MIT license.

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].