絕對奇怪的情況在創建線程,這裏的測試代碼:的Linux 2.6.30 uClibc的0.9.29在pthread_create 2胎面insted的只是一個
#include <stdint.h> /* C99 types */
#include <stdbool.h> /* bool type */
#include <stdio.h> /* printf, fprintf, snprintf, fopen, fputs */
#include <string.h> /* memset */
#include <signal.h> /* sigaction */
#include <time.h> /* time, clock_gettime, strftime, gmtime */
#include <sys/time.h> /* timeval */
#include <unistd.h> /* getopt, access */
#include <stdlib.h> /* atoi, exit */
#include <errno.h> /* error messages */
#include <math.h> /* modf */
#include <assert.h>
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET constants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h> /* gai_strerror */
#include <pthread.h>
void thread_up(void) {
printf("thread ....\n");
int loop=0;
while(loop<=7)
{
printf("loop...\n");
sleep(10);
loop++;
}
printf("Exit loop\n");
}
int main()
{
pthread_t thrid_up=0;
int i = pthread_create(&thrid_up, NULL, (void * (*)(void *))thread_up, NULL);
if (i != 0) {
printf("ERROR: [main] impossible to create upstream thread\n");
exit(1);
}
while(1)
{
sleep(10);
}
}
代碼產生的ps命令輸出如下(後./test &發射):
30214 root 704 S ./test
30215 root 704 S ./test
30216 root 704 S ./test
任何提示?
'ps'默認情況下不顯示線程,AFAIK。你是否用任何特殊的旗幟運行它?你確定你不只是運行你的程序的三個實例嗎?如果你將調用放到'pthread_create()'中,會發生什麼? – Hasturkun
我看不出有任何理由解決了這個問題。這是一個完全有效的問題。有人欠這個人回票。 –