Question: Write a C program to create two new pthreads: thread1 will withdraw from a shared account, and the thread2 will deposit into the same account.

Write a C program to create two new pthreads: thread1 will withdraw from a shared account, and the thread2 will deposit into the same account. Assume that the original balance is $500. The main thread will create the threads, and pass the amount to withdraw/deposit as the parameters to thread's runner function, and then wait for both threads to terminate. You may use a mutex variable (or semaphore) to protect the critical sections.

// declare global variables here

//main function ust

//initialize the global variables, mutex variables, semaphores,

// create threds and wait for them to terminate

// the amounts to withdraw and depsoti are command line parameters

int main(int argc, char **argv) {

}

//thread1: Write statements to implement thread1

void *withdraw (void *param) {

}

// thread2: Write statements to implement thread2

void * deposit (void *param) {

}

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!