Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

#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 ",tid);

gettimeofday(&tp_s1,&tzp_s1);

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

{

for (j=0;j

x=(i+1)*j;

printf(" ");

}

gettimeofday(&tp_e1,&tzp_e1);

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

printf("Total time %d diff=%d ",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 ");

else

{

if (scope== PTHREAD_SCOPE_PROCESS)

{

printf("PTHREAD_SCOPE_PROCESS ");

else

if (scope== PTHREAD_SCOPE_SYSTEM)

printf("PTHREAD_SCOPE_SYSTEM ");

else

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

}

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

{

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

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

}

for (i=0;i

pthread_join(tid[i],NULL);

gettimeofday(&tp_e,&tzp_e);

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

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions