오늘의 교훈 – Today’s lesson

[#M_ 한국어| 닫기 |
thread를 join하지 않으면 세그멘테이션 폴트가 나기도 한다.-_-;; 아우 이것 때문에 네트워크 숙제에 흥미가 확 떨어졌다가 다시 붙었다. 역시 코딩을 하다가 의욕을 떨어뜨리는 최악의 상황은 세그멘테이션 폴트가 나는데 그게 계속 나면 차라리 나은데 어떨 때는 나고 어떨 때는 안날 때. ㅎ

각설하고, 문제의 코드는

for(; i < SIZE; i++){
if(pthread_join(thread[i], NULL)){ // join threads
printf(“cannot join thread\n”);
}
}

아우, 병신 i를 0으로 리셋 안한 걸 깜빡 잊고 계속 없는 쓰레드를 join하고 있었으니 세그멘테이션 폴트가 나는 게 당연하지. 근데 저 부분이 아예 없어도 세그멘테이션 폴트가 난다.

아무튼, 저걸 해결하고 나니 쓰레드 안에서 sleep(5)가 안 먹던 것도 이제 먹는다. 근데 사실 아직도 왜 쓰레드들끼리 join하기를 기다려야 되는지는 잘 모르겠다. 일단은 그래야 되는 것으로 가정하고 숙제부터 마무리~_M#]

[#M_ English| Close |
Threre is some possibility of occurring segmentation fault if you forget to join thread-_-;; Because of that, I have lost an interest on network homework and recovered again. I think the worst situation during programming is when I can see segmentation fault sometimes(not always).

Anyway, the problem was,

for(; i < SIZE; i++){
if(pthread_join(thread[i], NULL)){ // join threads
printf(“cannot join thread\n”);
}
}

How foolish! I forgot to reset the variable i to 0 and continued joining threads. It was natural to meet segmentation fault. By the way, even though that part doesn’t exist, you may still meet segmentation.

Anyway, after solving that problem, sleep(5) function in the thread works. But I still don’t know why threads must be joined. Let’s assume that it is trivial, I have to complete homework~_M#]

3 thoughts on “오늘의 교훈 – Today’s lesson”

Leave a Reply to 김정훈 Cancel reply

Your email address will not be published. Required fields are marked *