This means that the default thread in which the main() function was running got completed and hence the process terminated as main() returned. So, why does this happen? Well, this happened because just before the second thread is about to be scheduled, the parent thread (from which the two threads were created) completed its execution. So we see that the log ‘Second thread processing’ is missing in case we remove the sleep() function. threadsīut if I run it with sleep() enabled then I see the output as : $. If I remove the sleep() function from the code above and then try to compile and run it, I see the following output : $. Printf("\n Thread created successfully\n") ĭid you observe the ‘sleep()’ function being used? Did you get a question about why sleep() is being used? Well if you did then you are at the correct place to get the answer and if you did not then also its going to be a good read ahead. Printf("\ncan't create thread :", strerror(err)) If we take the same example as discussed in part-II of this series : #includeĮrr = pthread_create(&(tid), NULL, &doSomeThing, NULL) Linux Threads Series: part 1, part 2, part 3 (this article). In this article we will mainly focus on how a thread is terminated. In the part-II (Thread creation and Identification) of the Linux Thread series, we discussed about thread IDs, how to compare two thread IDs and how to create a thread.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |