是的,Debian 上的 GCC 完全支持多线程编程。
下面从几个常见角度说明:
GCC(GNU Compiler Collection)在 Debian 中默认就支持 POSIX 线程(pthread),这是 Linux 下实现多线程的标准方式。
示例(C 语言):
#include <pthread.h>
#include <stdio.h>
void* thread_func(void* arg) {
printf("Hello from thread\n");
return NULL;
}
int main() {
pthread_t tid;
pthread_create(&tid, NULL, thread_func, NULL);
pthread_join(tid, NULL);
return 0;
}
编译时需要加 -pthread 参数:
gcc test.c -pthread -o test
✅ 在 Debian 上,
-pthread是推荐写法(同时处理编译和链接)。
如果你使用 C++11 及以上标准:
#include <thread>
#include <iostream>
void f() {
std::cout << "thread\n";
}
int main() {
std::thread t(f);
t.join();
}
编译:
g++ test.cpp -std=c++11 -pthread -o test
GCC 也支持 OpenMP:
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello\n");
}
编译:
gcc test.c -fopenmp -o test
sudo apt update
sudo apt install build-essential
build-essential 已包含 GCC、G++ 和必要开发库。
-pthread如果你有具体语言(C / C++ / Fortran)或使用场景(服务器、嵌入式、实时系统),我可以给更针对性的建议。