Question: Many current language specifications, such as for C and C++, are inadequate for multithreaded programs. This can have an impact on compilers and the correctness
Many current language specifications, such as for C and C++, are inadequate for multithreaded programs. This can have an impact on compilers and the correctness of code, as this problem illustrates. Consider the following declarations and function definition:
int global_positives = 0;
typedef struct list {
struct list *next;
double val;
} * list;
void count_positives(list l)
{
list p;
for (p = l; p; p = p -> next)
if (p -> val > 0.0)
++global_positives;
}
Now consider the case in which thread A performs
count_positives();
While thread B performs
++global_positives;
a. What does the function do?
b. The C language only addresses single-threaded execution. Does the use of two parallel threads create any problems or potential problems?
Step by Step Solution
3.30 Rating (165 Votes )
There are 3 Steps involved in it
a The function counts the number of positive eleme... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
451-C-S-D-B-O-S (53).docx
120 KBs Word File
