Code Monkey home page Code Monkey logo

cthreads's Introduction

CThreads

Cross(-platform) threading library, using pthread and Windows Threads.

Purpose

CThreads is an extremely portable threading library, allowing you to use the same code on Windows and Unix-like systems. It is based on pthread and Windows Threads, and provides a simple interface to use them.

API

  • cthreads_thread_create: Creates a new thread.
  • cthreads_thread_detach: Detaches a thread.
  • cthreads_thread_join: Joins a thread.
  • cthreads_thread_equal: Compares two thread structures for equality.
  • cthreads_thread_self: Retrieves the thread identifier of the current thread.
  • cthreads_thread_id: Retrieves the thread identifier of the specified thread.
  • cthreads_thread_exit: Exits a thread.
  • cthreads_mutex_init: Initializes a mutex.
  • cthreads_mutex_lock: Locks a mutex.
  • cthreads_mutex_trylock: Tries to lock a mutex without blocking.
  • cthreads_mutex_unlock: Unlocks a mutex.
  • cthreads_mutex_destroy: Destroys a mutex.
  • cthreads_cond_init: Initializes a condition variable.
  • cthreads_cond_signal: Signals a condition variable.
  • cthreads_cond_broadcast: Broadcasts a condition variable.
  • cthreads_cond_destroy: Destroys a condition variable.
  • cthreads_cond_wait: Waits on a condition variable.

Note

For internal information of what functions are used on certain platform, see cthreads.h file.

Usage

CThreads is simple and easy, with (most) functions of the same name as pthread, but with different arguments.

Warning

To ensure you don't use a field or function that are not available on your platform, you can use the following:

#ifdef CTHREADS_RWLOCK
 // Code using CThreads rwlock
#endif

Those macros are:

  • CTHREADS_THREAD_DWCREATIONFLAGS
  • CTHREADS_THREAD_STACKADDR
  • CTHREADS_THREAD_DETACHSTATE
  • CTHREADS_THREAD_GUARDSIZE
  • CTHREADS_THREAD_INHERITSCHED
  • CTHREADS_THREAD_SCHEDPOLICY
  • CTHREADS_THREAD_SCOPE
  • CTHREADS_THREAD_STACK
  • CTHREADS_MUTEX_BINITIALOWNER
  • CTHREADS_MUTEX_LPNAME
  • CTHREADS_MUTEX_PSHARED
  • CTHREADS_MUTEX_TYPE
  • CTHREADS_MUTEX_ROBUST
  • CTHREADS_MUTEX_PROTOCOL
  • CTHREADS_MUTEX_PRIOCEILING
  • CTHREADS_COND_BMANUALRESET
  • CTHREADS_COND_BINITIALSTATE
  • CTHREADS_COND_LPNAME
  • CTHREADS_COND_PSHARED
  • CTHREADS_COND_CLOCK
  • CTHREADS_RWLOCK

Note

Any function/field that is not listed there is available on all platforms.

Tested compilers and platforms

CThreads has been tested on the following compilers and platforms:

  • MSVC 2022, 2013 (Windows 10, 8.1)
  • Cygwin GCC 11.3.0 (Windows 10)
  • MinGW GCC 11.3.0 (Windows 10)
  • OpenWatcom from June 2022 (Windows NT 4)
  • GCC 11.3.0 (FreeBSD 11, 586)
  • GCC 8.3.0 (Linux 4.19.0 System/390 custom image)
  • Clang 10.0 (FreeBSD 586)
  • Clang & GCC 15.0.7 (Ubuntu 23.04, Linux 6.2.0-23-generic)
  • Clang & GCC ?.?.? (Arch Linux)
  • GCC 10.2.1-6 & Clang 11.0.1-2 (Raspbian GNU/Linux 11, Linux 6.1.21-v8+)
  • GCC 16.0.4 & Clang 16.0.4 (Termux 0.118.0, Android 13 - Galaxy A53 5G)
  • acomp SVR5 (UnixWare 7.1.1)
  • MSVC Visual Studio 97 (Windows NT 4.0 x86/Alpha/MIPS)
  • MSVC 4.2 (Windows NT 3.51)
  • MSVC 2.0 (Windows NT 3.1, Windows 95)
  • IBM XLC, C Set, various versions (AIX 3.2, AIX 4.3, AIX 5.1, AIX 7.2)
  • HP aCC, various versions (HP-UX 10.20, 11.11, 11.31)
  • MIPSpro C, various versions (IRIX 5.3, 6.2, 6.5.22)
  • Watcom 11.0 (Windows NT 4.0)
  • Digital Mars, various versions (Windows 2000)
  • IBM OS/390 C/C++ V2R10 (OS/390 2.10)
  • IBM XL C/C++ 1.3 (z/OS 1.6)

cthreads's People

Contributors

thepedroo avatar

Stargazers

 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.