Skip to content
프로젝트

소개

POSIX 스레드와 Win32 스레드를 기반으로 하는 이식성 높은 C11 스레드 구현입니다.

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

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.

관련 프로젝트 살펴보기

불러오는 중…