c - Posix Pthread mutual exclusion -


I have written my problem in the comments in the code.

I am trying to make my code parallel using pthreads. First of all, I want to write a lot of data in memory from multiple threads in parallel. After writing the data, I want to execute this data with the same thread. And after executing the data, I want to read it. And after these three tasks, I want to send this data to other files. And I want to repeat this process several times.

I appreciate any help you have. Thank you.

  #include & lt; Pthread.h & gt; # Include & lt; Stdio.h & gt; #define ARRAYSIZE 100 # defined NUMTHREADS 7 straight threads {int start, stop, id; Int * array; }; / * Task * / Zero * CAL (Zero * TD) {Straight Thread Data * Data = (Straight ThreadData *) TD to write, execute and read data; Int start = data-> Start; Int stop = data-> Stop; Int thread_id = Data - & gt; Id; Int i, s, counter; Counter = 0; (I = start; i & lt; stop; i ++) {printf ("Threads want to write data here by all threads (// ==; s <200; s ++) {// In loop 1,% D is writing data \ n ", thread_id); } // In this loop2, after the data written by all the threads in Loop 1, // data (i = start; i & lt; stop; i ++) {printf ("thread% d data is executing This is implemented by all threads in loop2 \ n ", thread_ID); } // In this loop 3, after reading the data / reading and loop 1 and loop 2 (i = start; i & lt; stop; i ++) {printf ("Thread% d reading data" N ", thread_id) is read; } // counter, I want to run this counter once per writing, executing and after reading the data. Counter = counter 1; Printf ("counter value is% d \ n", counter); } Return tap; } Int main (zero) {int array [ARRAYSIZE]; Pthread_t thread [NUMTHREADS]; Thread data data [NUMTHREADS]; Int i; Int. Carpaththread = (ARRAYSIZE + NUMTHREADS-1) / NUMTHREADS; / * Divide the work for the thread, prepare the parameter / / (i = 0; i & lt; NUMTHREADS; i ++) {data [i] .start = i * tasksPerThread; Data [i] .stop = (i + 1) * tasksPerThread; Data [i] .array = array; Data [i] .id = i; } / * The last thread should not go by the end of the array * / data [NUMTHREADS-1] .stop = ARRAYSIZE; / * For launch threads * / (i = 0; i     

I think you need mutual exclusion for the counter, before This should be a thread synchronization phase and that is enough.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -