- 论坛徽章:
- 0
|
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
void *smp_line(void *args)
{
char *s = (char *)args;
int i;
pthread_detach(pthread_self());
for ( ; ; )
printf("%s", s);
return NULL;
}
int main()
{
pthread_t t1, t2;
char *s1 = "AAAAA";
char *s2 = "BBBBB";
if (pthread_create(&t1, NULL, smp_line(s1), NULL)) {
fprintf(stderr, "Create thread t1 failed!\n");
abort();
}
if (pthread_create(&t2, NULL, smp_line(s2), NULL)) {
fprintf(stderr, "Create thread t2 failed!\n");
abort();
}
exit(0);
}
在FreeBSD 6.1下编译运行,为什么会一直输出“AAAAAAAAAAAAAAAAAAAA....”呢,我指望它交错输出“AAAAA”和“BBBBB”呢。
[ 本帖最后由 xfsoul 于 2006-5-21 14:52 编辑 ] |
|