I want to create one thread for each row of my 2D array. Then each thread should find the max value in given row, but I can’t wait for any thread to complete with pthread_join. So what should I do?
I want to create one thread for each row of my 2D array. Then
Share
From what I understand you want to split your 2D array into 1D arrays and pass them to threads, but you don’t know what to do when each of these threads finds maximum in its “own” array – and you don’t want to pass this value to
pthread_exit()and retrieve it bypthread_join()in the main thread.You could use global array managed by the main thread for storing these values. Here’s the idea (pseudocode):
Each thread finds local maximum
localMaxin given array (row) and stores it into arraymax.But at the end you will have to use
pthread_joinso that you know that all threads have finished their work.