If you are not familiar with threaded programming, below is a brief explanation of the code.
(The example on the slide uses pthread library to create a new thread of control from C code. Many of you might prefer more more syntax such as C++ standard library's std::thread, here's a tutorial:
The first thread, let's call it thread 1, is the main thread of the program. This thread calls pthread_create() to create a new thread of control. Let's call the second thread thread 2.
Thread 1 then calls sinx() on the second half of the array x (on N/2 elements starting with elements x[args.N]) You can see this from the arguments to sinx. When sinx returns thread 1 waits for the completion of thread 2.
Thread 2, when it is launched, immediately calls sinx on the first half of the array. (on N/2 elements)
If you are not familiar with threaded programming, below is a brief explanation of the code.
(The example on the slide uses pthread library to create a new thread of control from C code. Many of you might prefer more more syntax such as C++ standard library's
std::thread
, here's a tutorial:https://solarianprogrammer.com/2011/12/16/cpp-11-thread-tutorial/
In this code, there are two threads of control.
The first thread, let's call it thread 1, is the main thread of the program. This thread calls
pthread_create()
to create a new thread of control. Let's call the second thread thread 2.Thread 1 then calls
sinx()
on the second half of the arrayx
(on N/2 elements starting with elementsx[args.N]
) You can see this from the arguments tosinx
. Whensinx
returns thread 1 waits for the completion of thread 2.Thread 2, when it is launched, immediately calls
sinx
on the first half of the array. (on N/2 elements)