Enable -Wextra in tests.
This commit is contained in:
+37
-36
@@ -8,60 +8,61 @@
|
||||
#include "common.h"
|
||||
|
||||
struct arg2 {
|
||||
int status;
|
||||
pthread_t t1;
|
||||
int status;
|
||||
pthread_t t1;
|
||||
};
|
||||
|
||||
void *routine1(void *arg) {
|
||||
puts("Thread 1 spawned, waiting 1s.");
|
||||
sleep(1);
|
||||
puts("Thread 1 finished.");
|
||||
return strdup("message from thread 1");
|
||||
assert(arg == NULL);
|
||||
puts("Thread 1 spawned, waiting 1s.");
|
||||
sleep(1);
|
||||
puts("Thread 1 finished.");
|
||||
return strdup("message from thread 1");
|
||||
}
|
||||
void *routine2(void *arg_raw) {
|
||||
struct arg2 *arg = arg_raw;
|
||||
struct arg2 *arg = arg_raw;
|
||||
|
||||
puts("Thread 2 spawned, awaiting thread 1.");
|
||||
puts("Thread 2 spawned, awaiting thread 1.");
|
||||
|
||||
void *retval_raw;
|
||||
int status;
|
||||
void *retval_raw;
|
||||
int status;
|
||||
|
||||
if ((status = pthread_join(arg->t1, &retval_raw)) != 0) {
|
||||
arg->status = fail(status, "t1 join from thread 2");
|
||||
return NULL;
|
||||
}
|
||||
char *retval = retval_raw;
|
||||
|
||||
assert(strcmp(retval, "message from thread 1") == 0);
|
||||
|
||||
free(retval);
|
||||
|
||||
if ((status = pthread_join(arg->t1, &retval_raw)) != 0) {
|
||||
arg->status = fail(status, "t1 join from thread 2");
|
||||
return NULL;
|
||||
}
|
||||
char *retval = retval_raw;
|
||||
|
||||
assert(strcmp(retval, "message from thread 1") == 0);
|
||||
|
||||
free(retval);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
pthread_t t1;
|
||||
pthread_t t2;
|
||||
|
||||
int status;
|
||||
int status;
|
||||
|
||||
puts("Main thread.");
|
||||
puts("Main thread.");
|
||||
|
||||
if ((status = pthread_create(&t1, NULL, routine1, NULL)) != 0) {
|
||||
return fail(status, "t1 create");
|
||||
}
|
||||
if ((status = pthread_create(&t1, NULL, routine1, NULL)) != 0) {
|
||||
return fail(status, "t1 create");
|
||||
}
|
||||
|
||||
puts("Created thread 1.");
|
||||
puts("Created thread 1.");
|
||||
|
||||
struct arg2 arg = { .status = 0, .t1 = t1 };
|
||||
struct arg2 arg = { .status = 0, .t1 = t1 };
|
||||
|
||||
if ((status = pthread_create(&t2, NULL, routine2, &arg)) != 0) {
|
||||
return fail(status, "t2 create");
|
||||
}
|
||||
if ((status = pthread_create(&t2, NULL, routine2, &arg)) != 0) {
|
||||
return fail(status, "t2 create");
|
||||
}
|
||||
|
||||
if ((status = pthread_join(t2, NULL)) != 0) {
|
||||
return fail(status, "t2 join");
|
||||
}
|
||||
if ((status = pthread_join(t2, NULL)) != 0) {
|
||||
return fail(status, "t2 join");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user