Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Many current language specifications, such as for C and C++, areinadequate for m

ID: 3562886 • Letter: M

Question

Many current language specifications, such as for C and C++, areinadequate for multithreaded
programs.This can have an impact on compilers and the correctnessof code,
as this problem illustrates. Consider the following declarationsand 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. Doesthe use of two the
parallel threads, create any problems or potential problems?

Explanation / Answer

#include #include #define NTHREADS 4 #define N 1000 #define MEGEXTRA 1000000 pthread_attr_t attr; void *dowork(void *threadid) { double A[N][N]; int i,j; long tid; size_t mystacksize; tid = (long)threadid; pthread_attr_getstacksize (&attr, &mystacksize); printf("Thread %ld: stack size = %li bytes ", tid, mystacksize); for (i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote