Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain in your own words the following code: #include #include int value; void *my_thread(void *param); main (int argc, char *argv[]) {pthread_t tid; int retcode; //what

  1. Explain in your own words the following code:

#include

#include

int value;

void *my_thread(void *param);

main (int argc, char *argv[])

{pthread_t tid; int retcode;

//what does this do

if (argc != 2) {

fprintf (stderr, "usage: a.out ");

exit(0);

}

//what does this do

retcode = pthread_create(&tid,NULL,my_thread,argv[1]);

//what does this do

if (retcode != 0) {

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

exit (1);

}

// What does this do

pthread_join(tid,NULL);

printf ("I am the parent: Square = %d ", value);

} //main

// What does this do

void *my_thread(void *param)

  • {

int i = atoi (param);

printf ("I am the child, passed value %d ", i);

value = i * i;

pthread_exit(0);

  • }

  1. What would be the output of the executable of above program: if the following are input at the command prompt:
  2. ./a.out
  3. ./a.out 5

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

Step: 3

blur-text-image

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions