Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions