Question: / / Example 7 . 3 #include #include struct char _ print { char character; int count; } ; void * print ( void *
Example
#include #include
struct charprint
char character; int count;
;
void print void parameters
struct charprint p;
p struct charprint parameters; int i;
for i; i pcount ; i fputcpcharacter, stderr;
pthreadexitNULL;
int main
pthreadt tid; pthreadt tid;
struct charprint targs; struct charprint targs;
targs.character; targs.count ;
pthreadcreate&tid NULL, print, void &targs;
targs.character; targs.count ;
pthreadcreate&tid NULL, print, void &targs;
pthreadjointidNULL; pthreadjointidNULL;
marks Compile and run Example above and provide a sample output of the program.
marks Remove the two pthreadjoin function calls from Example recompile as follows:
$ gcc o example examplec l pthread then, run the program as follows:
$ example
What is the output of the program.
marks In question explain why are you getting such an output and how to fix it
marks Write a program that reports the scheduling behaviour of threads on a multiCPU system. Use the following function to report on the CPU on which a thread is scheduled:
#include #define GNUSOURCE int schedgetcpu
Your program must create three threads. Each thread will start in a separate function than the other threads. The general structure of the threadstartup function is that it will be in an infinite loop executing two statements:
Report the thread number first second, third along with the CPU it was scheduled on
Sleeps for seconds sleep
Note: To get an output that includes scheduling threads on multiple CPUs, the virtual machine running Ubuntu Linux has to be reconfigured.
If you're using VMWare Player, You can increase the number of CPUs available to the virtual machine by going to: Edit Virtual Machine Settings Hardware Tab Processors
and select the number of CPUs from the dropbox.
If you're using Virtual Box, go to: Machine Settings System Processor, and increase the number of processors in the text box.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
