Suppose you want to build a simple ATM application for depositing and withdrawing money safely from multiple ATMs simultaneously, and you want only one user/ATM to be updating a given account's balance at a time. Model each user/ATM as a thread, and write two functions, deposit() and withdraw(), each of which takes a struct of type Account, as declared below, and an unsigned integer amount as arguments, and updates the account balance in a thread-safe manner, returning the new account balance. If you need to, you can also write an initialization function with no arguments and no return value, called init, that initializes any variables needed to properly implement deposit and withdraw. You can assume that the initialization function would be called before any calls to either of the other functions. The declaration for the struct and the prototypes for the functions are as follows: typedef struct acc { unsigned int userid; /* unique ID */ char *user_name; unsigned int balance; } Account; /* pointer to string with user name */ void init(void); int deposit (Account *account, unsigned int amount); int withdraw (Account *account, unsigned int amount); You may want to use some of the following pthreads functions, which are listed in no particular order: pthread_create (pthread_t *tid, pthread_attr_t *attr, void * (*func) (void *), void *arg) pthread_join(pthread_t tid, void **val) pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) pthread_mutex-lock (pthread_mutex_t *mutex) pthread_mutex_unlock (pthread_mutex_t *mutex)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Suppose you want to build a simple ATM application for depositing and withdrawing money safely
from multiple ATMs simultaneously, and you want only one user/ATM to be updating a given account's
balance at a time. Model each user/ATM as a thread, and write two functions, deposit() and withdraw(),
each of which takes a struct of type Account, as declared below, and an unsigned integer amount as
arguments, and updates the account balance in a thread-safe manner, returning the new account balance.
If you need to, you can also write an initialization function with no arguments and no return value, called
init, that initializes any variables needed to properly implement deposit and withdraw. You can assume
that the initialization function would be called before any calls to either of the other functions.
The declaration for the struct and the prototypes for the functions are as follows:
typedef struct acc {
unsigned int userid; /* unique ID */
char *user_name;
unsigned int balance;
} Account;
/* pointer to string with user name */
void init(void);
int deposit (Account *account, unsigned int amount);
int withdraw (Account *account, unsigned int amount);
You may want to use some of the following pthreads functions, which are listed in no particular order:
pthread_create (pthread_t *tid, pthread_attr_t *attr, void * (*func) (void *), void *arg)
pthread_join(pthread_t tid, void **val)
pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
pthread_mutex_lock (pthread_mutex_t *mutex)
pthread_mutex_unlock (pthread_mutex_t *mutex)
Transcribed Image Text:Suppose you want to build a simple ATM application for depositing and withdrawing money safely from multiple ATMs simultaneously, and you want only one user/ATM to be updating a given account's balance at a time. Model each user/ATM as a thread, and write two functions, deposit() and withdraw(), each of which takes a struct of type Account, as declared below, and an unsigned integer amount as arguments, and updates the account balance in a thread-safe manner, returning the new account balance. If you need to, you can also write an initialization function with no arguments and no return value, called init, that initializes any variables needed to properly implement deposit and withdraw. You can assume that the initialization function would be called before any calls to either of the other functions. The declaration for the struct and the prototypes for the functions are as follows: typedef struct acc { unsigned int userid; /* unique ID */ char *user_name; unsigned int balance; } Account; /* pointer to string with user name */ void init(void); int deposit (Account *account, unsigned int amount); int withdraw (Account *account, unsigned int amount); You may want to use some of the following pthreads functions, which are listed in no particular order: pthread_create (pthread_t *tid, pthread_attr_t *attr, void * (*func) (void *), void *arg) pthread_join(pthread_t tid, void **val) pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) pthread_mutex_lock (pthread_mutex_t *mutex) pthread_mutex_unlock (pthread_mutex_t *mutex)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY