Skip to content

Commit 781dd8a

Browse files
committed
make the use of 1st arg of pthread_create() wrong again
so that the code matches the top level comment
1 parent fe46a5c commit 781dd8a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pthreads/wrong-use-of-arg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
1717
*/
1818

19-
#include <err.h>
20-
#include <pthread.h>
2119
#include <stdio.h>
2220
#include <string.h>
2321
#include <unistd.h>
22+
#include <err.h>
23+
#include <pthread.h>
2424

2525
#define NUM_THREADS 5
2626
#define NUM_LOOPS 3
@@ -39,7 +39,7 @@ int
3939
main(int argc, char *argv[])
4040
{
4141
int i, e, yield = 0;
42-
pthread_t t[NUM_THREADS];
42+
pthread_t t;
4343
void *p;
4444

4545
printf("Run with any argument to use sched_yield().\n");
@@ -51,7 +51,7 @@ main(int argc, char *argv[])
5151

5252
for (i = 0; i < NUM_THREADS; ++i) {
5353
/* Note we are forgetting the created threads. */
54-
pthread_create(t + i, NULL, thread, &i);
54+
pthread_create(&t, NULL, thread, &i);
5555
if (yield)
5656
sched_yield();
5757
}
@@ -64,7 +64,7 @@ main(int argc, char *argv[])
6464

6565
for (int j = 0; j < NUM_THREADS; ++j) {
6666
printf("Joining thread (%d)", j);
67-
if ((e = pthread_join(*(t + j), &p)) != 0)
67+
if ((e = pthread_join(t, &p)) != 0)
6868
warnx(": error: %s", strerror(e));
6969
else
7070
printf(".\n");

0 commit comments

Comments
 (0)