Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions