Skip to content

Illusionna/TinyCThread-Tutorial

Repository files navigation

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
    

阅读顺序

  1. hello-world
  2. thread-exit
  3. access-same-data
  4. performance-test

编译

教程所有的 C 语言文件在开头都提供了编译指令,你可以仿照学习,例如 performance-test.c 文件。

Windows

gcc -o performance-test.exe performance-test.c ./tinycthread/tinycthread.c

Linux

gcc -o performance-test.out performance-test.c ./tinycthread/tinycthread.c -pthread

macOS

gcc -o performance-test.out performance-test.c ./tinycthread/tinycthread.c -pthread

Windows 开启 GCC 编译优化

gcc -O3 -o performance-test.exe performance-test.c ./tinycthread/tinycthread.c

致谢

如果你觉得本教程对你有所帮助,欢迎给 TinyCThread 作者 star,我已经点赞了!🤭

About

C Language Multi-threading Tutorial for Beginners! C 语言 TinyCThread 多线程入门教程。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages