• Stars
    star
    237
  • Rank 169,885 (Top 4 %)
  • Language
    C
  • Created about 12 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Portable C11 threads implementation over POSIX threads and win32 threads.

Trivial C11 threads.h implementation over POSIX threads, and not-so-trivial implementation over Win32 threads.

Rationale

Even though GCC provides the threading features required by the C11 standard (like atomics, and thread-local storage), GNU libc, still does not implement the necessary library functions of the standard C thread API. Other popular platforms similarly lack support for the C11 thread functions, like Microsoft's C runtime library on Windows.

If you're starting a new multithreaded project in C right now, it would make sense to use the standard C way of using threads instead of a mishmash of various platform-specific APIs. So until the system libc adds support for it, we need a stopgap that works exactly as the C standard describes.

License

Authors:

I place this piece of code in the public domain. Feel free to use as you see fit. I'd appreciate it if you keep my name at the top of the code somewhere, but whatever.

How to use

With POSIX threads

On UNIX systems, or on Windows with a 3rd party pthreads library, c11threads is implemented as a thin wrapper of static inline functions over pthreads.

No installation or compilation necessary; just drop c11threads.h into your project source tree, and don't forget to link with -lpthread. On some platforms it might be required to also pass the -pthread flag to the compiler.

If your compiler does not support the inline keyword, define C11THREADS_INLINE to whatever equivalent keyword the compiler provides, or to the empty string to make all the functions simply static.

If you wish to use the pthreads implementation on Windows, in preference to the native win32 one, you need to define C11THREADS_PTHREAD_WIN32.

With Win32 threads

To use C11 threads over the Windows threads API, beyond adding c11threads.h to your project, you also need to compile c11threads_win32.c as part of your build. Additionally, if you're in a situation where letting c11threads keep resources for the duration of the process lifetime is not desirable, you can call c11threads_destroy_win32() to free them manually at any point, when you're done with it.

Test program

There's a simple test program under test/. To build it on UNIX (GNU/Linux, FreeBSD, MacOSX, whatever), simply change into the test directory and type make.

To build the test program on Windows with MSVC using native win32 threads, setup the build environment (usually there's a batch file called vcvars*.bat, run it in a console), and use microsoft nmake to build: nmake -f Makefile.msvc.

Contact

Main project site: https://github.com/jtsiomb/c11threads

Feel free to send corrections, patches, trendy social pull requests, pictures of your cat wearing santa hats, any good porn links, or investment opportunities with Nigerian ex-royals... It's all good.

More Repositories

1

kdtree

A simple C library for working with KD-Trees
C
392
star
2

libdrawtext

Simple library for fast anti-aliased text rendering in OpenGL
C
86
star
3

xlivebg

Live wallpapers for the X window system
C
80
star
4

usbamigafloppy

USB floppy controller for Amiga disks
C
64
star
5

miniglut

minimal single-file GLUT implementation without unnecessary dependencies
C
60
star
6

pcboot

Bootable PC demo/game kernel
C
47
star
7

a500kbd

Amiga 500 PS/2 controller for external keyboard
C
41
star
8

termtris

Tetris game for terminals
C
37
star
9

libimago

Simple C library for loading and saving images in multiple file formats
C
35
star
10

kernel

A minimal UNIX kernel project for x86 PCs
C
35
star
11

shadertoy-view

A native shadertoy-compatible GLSL fragment shader previewer
C++
32
star
12

fsnav

3D filesystem navigator inspired by SGI FSN
C++
31
star
13

m68kcomputer

Homebrew Motorola 68010 computer
C
24
star
14

gbatris

Tetris for the GameBoy Advance
C
21
star
15

ubertk

ubertk (utk) is an API-agnostic C++ GUI toolkit targetted mainly towards graphics applications.
C++
21
star
16

gbs-cgaega

CGA/EGA input board for the GBS-8200 VGA converter
Awk
19
star
17

libgoatvr

modular virtual reality abstraction library
C++
18
star
18

assfile

C library for accessing assets (read-only data) from many different sources, with an fopen/fread-like API.
C
16
star
19

c-ray

Minimal C raytracer widely used as a CPU benchmark
C
15
star
20

colcycle

Color-cycling image viewer
C
13
star
21

emurom

ROM emulator. Accepts ROM images through USB and acts as a parallel ROM chip.
C
13
star
22

shapeblobs

3D metaballs effect in a continuously changing shaped window
C
12
star
23

3dxdisp

Simple library for controlling the LCD of the 3Dconnexion SpacePilot 6-dof input device
C
11
star
24

meshgen

Procedural 3D mesh generation tool
C++
11
star
25

gph-cmath

C math library for graphics
C++
11
star
26

sgikbd

PS/2 keyboard/mouse converter for old Silicon Graphics computers.
C
10
star
27

libresman

Multithreaded resource data file management library
C
10
star
28

paintless

A pointless VGA paint program for DOS
C
9
star
29

visftp

Visual FTP client with dual-pane text-based UI for DOS and UNIX.
C
8
star
30

m68kcomputer2

Homebrew 32bit computer based on the Motorola 68030
Makefile
8
star
31

gph-math

C++ math library for graphics programs
C++
8
star
32

s3virgedriver

S3 Virge driver hack
C
8
star
33

libpsys

Reusable particle system library
C
8
star
34

rbtree

Simple balanced binary search tree (red-black tree) library
C
8
star
35

libtreestore

C library for reading/writing hierarchical data in a json-like text or a chunk-based binary format
C
8
star
36

tinyblobray

Tiny metaball ray-marching in x86/x87 assembly
Assembly
7
star
37

libvmath

A mature C and C++ math library for 3D graphics http://nuclear.mutantstargoat.com/sw/libvmath/
C++
7
star
38

cyberay

Realtime raytraced game experiment
C
7
star
39

frapix

Framerate monitoring and screen capture for UNIX OpenGL programs
C
7
star
40

auplay

Simple DOS audio player / SoundBlaster 16 example code.
C
7
star
41

gbasys

gameboy advance hardware abstraction library
C
7
star
42

tinyweb

Tiny web server library and daemon
C
6
star
43

gba-mtglife

Magic the Gathering life counter for the GameBoy Advance
C
6
star
44

libanim

General-purpose hierarchical keyframe animation library
C
6
star
45

capsmap

DOS TSR for remapping caps lock
Assembly
6
star
46

goat3d

3D scene, character, and animation file format specification, library, and tools.
C
5
star
47

bootsplash

Boot splash-screen effect & boot chain-loader for IBM PC compatible computers.
Assembly
5
star
48

csgray

Simple CSG ray tracer
C
4
star
49

cubemapper

Tool for converting panoramic images to cubemaps
C++
4
star
50

rpikern

Raspberry Pi kernel hacking experiments
C
4
star
51

dos_demo_framework

Framework for writing retro demos for DOS pentium/pentium2-class PCs.
C
4
star
52

curvedraw

Simple curve drawing program
C++
4
star
53

vrtris

Virtual Reality Tetris (VR optional)
C
4
star
54

texpand

Texture pre-processing tool for expanding texels into unused areas, to avoid filtering artifacts.
C
4
star
55

dropcode

random useful pieces of code to drop in other programs
C
4
star
56

clray

Realtime GPU (OpenCL) polygon mesh raytracer
C++
3
star
57

visor

lightweight system-independent embeddable text editor framework & text editor
C
3
star
58

metasurf

A library for implicit surface polygonization
Objective-C
3
star
59

bootcard

Bootable wedding card for our friends Michael (Samurai) and Athena
C
3
star
60

henge

A simple but functional OpenGL 3D engine
C++
3
star
61

stereowrap

OpenGL stereoscopic visual wrapper
C
3
star
62

retrobench

Multi-platform framebuffer drawing performance benchmark for retro-PCs
C
3
star
63

drippy

Datafile ripper/carver
C
2
star
64

nixiedisp

USB nixie tube numeric display
C
2
star
65

lspart

list partitions on a disk or image file
C
2
star
66

comptex

Tool for converting images to various OpenGL compressed texture formats, and saving them in a simple file format.
C
2
star
67

tavli3d

A 3D client for multiplayer backgammon and similar "tavli" games
C
2
star
68

3dengfx

An old 3D engine, used for The Lab and MLFC demos in the 2000s.
C
2
star
69

retroray

retro-style deterministic renderer with integrated modeller/scene editor.
C
2
star
70

z80comp2

Another simple Z80 8bit computer
C
2
star
71

stereotunnel

Stereoscopic tunnel effect for iOS and Android
C
2
star
72

libwcam

Simple C library for video input on GNU/Linux
C
2
star
73

retrowinjam24

Retro Win32 game jam 2024 entry
C
1
star
74

alphaclock

Pointless eye-candy transparent desktop clock
Objective-C
1
star
75

mtexp

an old library for setting up fixed function OpenGL multitexturing with simple expressions
C
1
star
76

goatkit

Themable and animated UI widget toolkit library for games
C++
1
star
77

phoneline

system for managing annoying ringing phones
C
1
star
78

moltenmetal

A tech demo for my experimental COM32 protected mode kernel for DOS
C
1
star