Question: Creates a thread my_thread . The job of the thread my_thread is to count how many lines exist in the file data.txt and return the

Creates a thread my_thread. The job of the thread my_thread is to count how many lines exist in the file data.txt and return the number of lines to the calling process. The process then prints this number to the screen.

int { main() Open the file data txt and obtain the file handler fh; Create a thread my_thread using 

int { main() Open the file data txt and obtain the file handler fh; Create a thread my_thread using pthread_create; pass fh to my_thread, Wait until my_thread terminates, using pthread_join; Print out how many lines exist in data txt. } Basic structure of thread_function.c: void *count_lines(void *arg) { Obtain fh from arg, Count how many lines num_lines exist in fh; Close fh; Return num_lines For information about pthread_create and pthread_join:

Step by Step Solution

3.55 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Below is an example program in C that accomplishes the task you described using POSIX thre... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!