Question: Suppose that a program has two threads, each executing the get _ account function, shown below. Identify a race condition in this code. int accounts

Suppose that a program has two threads, each executing the get_account function, shown below. Identify a race condition in this code.
int accounts[LIMIT]; int account count =0;
void * get_account(void "tid){
char *lineptr = NULL;
size_t len =0;
while (account_count LIMIT)
{
// Read user input from terminal and store it in lineptr
getline(&lineptr, &len, stdin):
// Convert user input to integer
// Assume user entered valid integer value
int entered_account = atoi(lineptr);
accounts[account_count]= entered_account;
}
account count++;
// Deallocate memory that was allocated by getline call
free(lineptr):
return NULL; }
 Suppose that a program has two threads, each executing the get_account

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!