The example uses two worker threads: one for addition and another for subtraction. Consequently, we'll need two separate Wasm modules. Create a folder named /lib in your /parallel-wasm directory. Within the /lib directory, create a file named add.c and populate it with the following contents:
int calculate(int firstVal, int secondVal) {
return firstVal + secondVal;
}
Create another file in /lib named subtract.c and populate it with the following contents:
int calculate(int firstVal, int secondVal) {
return firstVal - secondVal;
}
Note that the function name in both files is calculate. This was done so we don't have to write any conditional logic within the worker code to determine the Wasm function to call. The algebraic operation is tied to a worker, so when we need to add two numbers, the _calculate() function will be called in the addWorker. This will become clearer when we review the JavaScript portion of the code, which we'll cover next.