Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The answer to 12.16 is wrong #88

Open
Eslamzaid opened this issue Sep 2, 2024 · 0 comments
Open

The answer to 12.16 is wrong #88

Eslamzaid opened this issue Sep 2, 2024 · 0 comments

Comments

@Eslamzaid
Copy link

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;
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant