Create a program using thread functions to create, synchronize and…

Question Answered step-by-step Create a program using thread functions to create, synchronize and… Create a program using thread functions to create, synchronize and terminate threads. What To DoAssume that you have the following functions:initque();int enque(data_t * dt);double proc(char * ar); where data_t is a structure: struct data_t{  double val;  pthread_t id;  int index; };Function val = proc(char * ar) receives an array of 128 bytes and returns one double value val. This function may be used by several threads at the same time. Function enque(struct data_t * dt) creates a new element, copies into it the data from the structure pointed by dt and enques it into a queue which has been created by a call to initque(). Function enque() may only be used by one thread at a time.Write the C code for the main thread function main() and the C code for two identical worker threads called work(). You do not have to write the code for initque(), enque() or proc().The program has a global variable count and two functions main() and work().int count;int main (int argc, char ** argv) { }void *work (void * arg) { } The main thread should work as follows:it ••itititis called with two arguments like test abc xyzthe two arguments are names of files in the current directoryinitializes count to 0 and initializes the queueopens the two files for readingcreates two threads, both running function work(), and gives to each thread (as•• it •Each ofititititthe first thread gets the file descriptor of the first file and the second threadgets the file descriptor of the second filewaits for the two threads to terminate, prints the value of count and then exitsit closes the corresponding file when a thread terminatesthe threads should work as follows:reads 128 bytes from the open filecalls function proc() which returns a value in some variableincrements global variable countstores in a variable of type struct data_t the value returned from the call toan argument) the file descriptor of one of the two open filesproc(), its own thread id and the value of global variable count obtained from theincrement just performedit calls function enque() to enque the new information• notice that enque() copies the information from the variable of type struct data_t to a new element in the queue, so that you can reuse the variableit repeats the above steps until it encounters end of fileit terminates if it reads fewer than 128 bytes or it encounters end of fileNotesA program that does not use threads will not get credit.Assume that all system calls return with no errors (files exist, threads created, etc.) Computer Science Engineering & Technology Object-Oriented Programming CS 400 Share QuestionEmailCopy link Comments (0)