QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 756|回复: 0

请教,关于KDevlop下多线程编程

[复制链接]
发表于 2005-8-29 11:33:18 | 显示全部楼层 |阅读模式
请教高手:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>

void *thread_function(void *arg);

char message[] = "Hello World";

int main() {
int res;
pthread_t a_thread;
void *thread_result;
res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
if (res != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("Waiting for thread to finish...\n");
res = pthread_join(a_thread, &thread_result);
if (res != 0) {
perror("Thread join failed");
exit(EXIT_FAILURE);
}
printf("Thread joined, it returned %s\n", (char *)thread_result);
printf("Message is now %s\n", message);
exit(EXIT_SUCCESS);
}

void *thread_function(void *arg) {
printf("thread_function is running. Argument was %s\n", (char *)arg);
sleep(3);
strcpy(message, "Bye!");
pthread_exit("Thank you for the CPU time");
}

在Red Hat Linux 10.0的KDevlop下不能通过,是何原因?
现象:
在kdevelop中上面的程序编译通过,但连接时pthread_create,pthread_join无法连接.用cc _D_REENTRANT threadtest.c -o threadtest -lpthread可顺利通过.请高手指教.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-3 04:28 , Processed in 0.042910 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表