Question: Write two basic C programs to add two numbers. One program using using pthreads and another program using kthreads functions. Students are encouraged to use

Write two basic C programs to add two numbers. One program using using pthreads and another program using kthreads functions. Students are encouraged to use and enhance the sample code provided below as per their coding standards. This assignment is to learn thread creation and join functions.

Grading information and instructions:

Pthreads program 10 points

Kthreads program 10 points

Execution and output Screenshots 10 points

Sample program structure: #include #include #include /* This is our thread function. */ int sum = 0; //Declare a global variable to store the results, sum void *threadFunc(void* p) { //Write your code here to print each variable and sum values } int main(void) { pthread_t thread1, thread2; // Thread declaration int *x = malloc (sizeof(*x)); //Use array or two variables as per your convenient int *y = malloc (sizeof(*y)); *x = 10; *y = 2; /* Create worker thread */ //write the thread creation function /* wait for our thread to finish before continuing */ //write thread join function printf("main() is running. "); return 0; } Hints: If you are using an array, create only one thread function to pass an array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!