Skip to content

The answer to 12.16 is wrong #88

@Eslamzaid

Description

@Eslamzaid

The answer to 12.16 is wrong because the homework states that creates and reaps n joinable peer threads

and the solution to this should be:

#include "csapp.h"
void *thread(void *vargp);

#define DEFAULT 4

int main(int argc, char* argv[]) {
  int N;
  if (argc > 2)
    unix_error("too many param");
  else if (argc == 2)
    N = atoi(argv[1]);
  else
    N = DEFAULT;

  int i;
  pthread_t tid;
  for (i = 0; i < N; i++) {
    Pthread_create(&tid, NULL, thread, NULL);
  } 
  for(i = 0; i < N; i++) {
    Pthread_join(tid[i], NULL);
   }
}

void *thread(void *vargp) {
  printf("Hello, world\n");
  return NULL;
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions