C Language Multi-Threading Tutorial for Beginners!
C 语言 TinyCThread 多线程入门教程!
这是 C 语言库 TinyCThread 的基础教程,仓库总大小约 60KB。它非常简约,不需要安装第三方依赖,即可在 Windows、Linux、macOS 操作系统上运行。该教程代码包含“线程间关系”、“互斥锁”、“数组求和”三个版块,为 C 语言多线程初学者入门。欢迎大家一起学习交流改进!
-
建议使用 GNU gcc 或 MinGW-W64 gcc 编译器,当然,你也可以选择 Tiny C Compiler 编译器。
-
芯片架构建议 64 位。
-
操作系统建议 Windows 10、Windows 11。
-
下载源代码仓库,并进入工作区目录。
git clone https://github.com/Illusionna/TinyCThread-Tutorial.git
- hello-world
- thread-exit
- access-same-data
- performance-test
教程所有的 C 语言文件在开头都提供了编译指令,你可以仿照学习,例如 performance-test.c 文件。
Windows
gcc -o performance-test.exe performance-test.c ./tinycthread/tinycthread.cLinux
gcc -o performance-test.out performance-test.c ./tinycthread/tinycthread.c -pthreadmacOS
gcc -o performance-test.out performance-test.c ./tinycthread/tinycthread.c -pthreadWindows 开启 GCC 编译优化
gcc -O3 -o performance-test.exe performance-test.c ./tinycthread/tinycthread.c如果你觉得本教程对你有所帮助,欢迎给 TinyCThread 作者 star,我已经点赞了!🤭