pthread_create함수 잘 잘아시는님 ㅠㅠ 도와주세요
#include
#include
#define NUM_THREADS 3
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n",tid);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0;t
printf("In main: creating thread %ld\n",t);
rc = pthread_create(&threads[t],NULL,PrintHello,(void *)t);
if(rc){
printf("ERROR; return code from pthread_create() is %d\n",rc);
exit(-1);
}
}
/*Last thing that main() should do */
Pthread_exit(NULL);
}
출력 결과가 어케되나요?
제 생각에는
In main: creating thread 0
Hello World! It's me, thread #0! -> 순서는 밑에 줄 어디일지 모름
In main: creating thread 1
Hello World! It's me, thread #1! -> 순서는 밑에 줄 어디일지 모름
In main: creating thread 2
Hello World! It's me, thread #2! -> 순서는 밑에 줄 어디일지 모름
이거 맞나요? 아니면 t도 공유된 변수이기 때문에 출력결과가 또 다르게 나오나요???
ㅠㅠ 아시는분 설명좀 해주시면 정말 감사하겠습니다.
댓글 달기