Coder Social home page Coder Social logo

exbotanical / lib.thread Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 37 KB

Bespoke POSIX threads, mutexes, wait queues, thread pools, and semaphores for the C programming language.

License: MIT License

Makefile 2.97% Shell 7.12% C 89.91%
multithreading mutex thread-synchronization thread-pool condition-variable semaphore

lib.thread's Introduction

lib.thread

A library of custom threading data structures, including stateful POSIX threads, mutexes, wait queues, and semaphores.

Currently Implemented Constructs

  • stateful POSIX threads
  • semaphores (weak)
  • thread barrier
  • suspension threads
  • generic thread pool

Upcoming Constructs

  • pausable thread
  • semaphores (strong)
  • generic wait queue

Install

Via clib:

clib install exbotanical/lib.thread

From Source:

git clone https://github.com/exbotanical/lib.thread
cd lib.thread && make

Dynamic Linking

Linking to lib.thread:

# 1) include and use lib.thread in your project
# 2) generate object file for your project
gcc -I ../path/to/libthread -c main.c -o main.o
# 3) generate shared object file
make
# 4) link your project to lib.thread (and libbsd, also required here)
gcc -o main main.o -L../path/to/libthread -llibthread -lbsd
# you may need to add the lib location to your PATH

Linking to lib.thread on Windows:

# 1) include and use lib.thread in your project
# 2) generate object file for your project
gcc -I ../path/to/libthread -c main.c -o main.o
# 3) generate shared object file
make win
# 3) link your project to lib.thread
gcc -o main.exe main.o -L /path/to/lib.thread -llib_thread.dll
# you may need to add the lib location to your PATH

Documentation and API

Thread Barriers

A thread barrier is a thread synchronization data structure that blocks all threads at a specified critical section until a specified threshold of threads arrives at the barrier point.

For example, if your program has a section that must wait for a number of tasks to be completed before proceeding, you might use a thread barrier.

Thread Pools

A thread pool is a data structure that holds suspended threads, each ready to resume and execute tasks.

Thread pools are useful because we are able to maintain initialized threads for the duration of a process without re-invoking pthread_create, an expensive wrapper for the clone system call.

Instead, threads are suspended after finishing their respective routines; we can call them back into the main thread's context and assign to them new work whenever we want to.

Find example usage of the thread pool API here

lib.thread's People

Contributors

exbotanical avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.