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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started