CSCI.4210 Operating Systems
Fall, 2004
Exercise 6.1, Threads

If a thread wants to return more than one value, you can create a structure with all of the return values, and return a pointer to an instance of this structure. Here is some code. Fill in the two sections
/* On some systems you will need to link to the pthread library by
   appending -l pthread to the compile line */


struct thedata {
  int x;
  char s[32];
void *threadroutine(void *arg)
  struct thedata *t = (struct thedata *)malloc(sizeof(struct thedata));
  t->x = 17;
  strcpy(t->s,"Hello world!");

int main()
  struct thedata *q;
  pthread_t n;
  int retval;

  retval = pthread_create(&n,NULL,threadroutine,NULL);
  if (retval < 0) {
    printf("error, could not create thread\n");
       write code here to get the return value from the
       thread and display the results.  Make sure that
       your code does routine error checking

RCS email: