Assignment requires that you should create a virtual machine in AWS (Amazon Web Services) to develop your programs to examine the performance of different pthread contention scope. Try to adopt two different pthread contention scope, process-contention scope, and system-contention scope, execute and compute the average turnaround time. Problem Statement According to the code attached in the document, rewrite the function runner that l The value of MAX is the last 8 number of your student ID l Display the turnaround time of each pthread of each scheduling algorithm l Please discuss the results of these scheduling algorithms. Code MUST BE WRITTEN IN C/C++ #include #include #include #define NUM_THREADS 5 struct timeval tp_s, tp_e; struct timezone tzp_s, tzp_e; void *runner(void *param)    {    int i=0,j=0;    long x;    pthread_t tid= pthread_self();    struct timeval tp_s1, tp_e1;    struct timezone tzp_s1, tzp_e1;    printf(" %d created\n",tid);    gettimeofday(&tp_s1,&tzp_s1);    for (i=0;i<1000;i++)       {       for (j=0;j

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

Assignment requires that you should create a virtual machine in AWS (Amazon Web Services) to develop your programs to examine the performance of different pthread contention scope. Try to adopt two different pthread contention scope, process-contention scope, and system-contention scope, execute and compute the average turnaround time.

Problem Statement

According to the code attached in the document, rewrite the function runner that

l The value of MAX is the last 8 number of your student ID

l Display the turnaround time of each pthread of each scheduling algorithm

l Please discuss the results of these scheduling algorithms.

Code MUST BE WRITTEN IN C/C++

#include <pthread.h>

#include <stdio.h>

#include <sys/time.h>

#define NUM_THREADS 5

struct timeval tp_s, tp_e;

struct timezone tzp_s, tzp_e;

void *runner(void *param)

   {

   int i=0,j=0;

   long x;

   pthread_t tid= pthread_self();

   struct timeval tp_s1, tp_e1;

   struct timezone tzp_s1, tzp_e1;

   printf(" %d created\n",tid);

   gettimeofday(&tp_s1,&tzp_s1);

   for (i=0;i<1000;i++)

      {

      for (j=0;j<MAX;j++)

          x=(i+1)*j;

      printf(" ");

      }

   gettimeofday(&tp_e1,&tzp_e1);

   printf("Execution time %d diff=%d\n",tid,tp_e1.tv_sec-tp_s1.tv_sec);

   printf("Total time %d diff=%d\n",tid,tp_e1.tv_sec-tp_s.tv_sec);

   pthread_exit(0);

   }

int main(int argc, char *argv[])

   {

   int i, scope;

   pthread_t tid[NUM_THREADS];

   struct sched_param p;

   pthread_attr_t attr;

   int sched_policy=0;

   pthread_attr_init(&attr);

   if (pthread_attr_getscope(&attr, &scope )!= 0)

      fprintf(stderr, "Unable to get scheduling scope\n");

   else

      {

      if (scope== PTHREAD_SCOPE_PROCESS)

         {

         printf("PTHREAD_SCOPE_PROCESS\n");

      else

         if (scope== PTHREAD_SCOPE_SYSTEM)

            printf("PTHREAD_SCOPE_SYSTEM\n");

         else

            fprintf(stderr, "Illegal scope value.\n");

      }

   pthread_attr_setscope(&attr,PTHREAD_SCOPE_PROCESS);//PTHREAD_SCOPE_SYSTEM); you must change the contention scope.

   gettimeofday(&tp_s,&tzp_s);

   for (i=0;i<NUM_THREADS;i++)

      {

      if (pthread_create(&tid[i],&attr,runner,NULL)!=0)

         fprintf(stderr, "Unable to create a thread\n");

      }

   for (i=0;i<NUM_THREADS;i++)

     pthread_join(tid[i],NULL);

   gettimeofday(&tp_e,&tzp_e);

   printf("Total time =%d\n",tp_e.tv_sec-tp_s.tv_sec);

   }

Expert Solution
steps

Step by step

Solved in 2 steps with 3 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