Skip to content

Commit

Permalink
get started on homework12
Browse files Browse the repository at this point in the history
  • Loading branch information
lemorage committed Oct 30, 2023
1 parent ac4add7 commit cd7c0fa
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions hw12/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#### 12.16
```c
#include "csapp.h"
void *thread(void *vargp);

int main(int argc, char **argv)
{
int n = atoi(argv[1]);
if (n <= 0) {
fprintf(stderr, "Number of threads must be a positive integer.\n");
exit(1);
}

pthread_t *tids = (pthread_t *)Malloc(n * sizeof(pthread_t));

for (int i = 0; i < n; ++i)
Pthread_create(&tids[i], NULL, thread, NULL);

for (int i = 0; i < n; ++i)
Pthread_join(tids[i], NULL);

Free(tids);
exit(0);
}

void *thread(void *vargp) /* Thread routine */
{
printf("Hello, world!\n");
return NULL;
}
```
#### 12.17
#### 12.18
#### 12.19
#### 12.20
#### 12.21
#### 12.22
#### 12.23
#### 12.24
#### 12.25
#### 12.26
#### 12.27
#### 12.28
#### 12.29
#### 12.30
#### 12.31
#### 12.32
#### 12.33
#### 12.34
#### 12.35
#### 12.36
#### 12.37
#### 12.38
#### 12.39

0 comments on commit cd7c0fa

Please sign in to comment.