Projet_SETI_RISC-V/riscv-gnu-toolchain/gdb/sim/testsuite/cris/c/thread3.c
2023-03-06 14:48:14 +01:00

46 lines
846 B
C

/* Compiler options:
#cc: additional_flags=-pthread
#progos: linux
To test sched_yield in the presencs of threads. Core from ex1.c. */
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
static void *
process (void *arg)
{
int i;
for (i = 0; i < 10; i++)
{
if (sched_yield () != 0)
abort ();
}
return NULL;
}
int
main (void)
{
int retcode;
pthread_t th_a, th_b;
void *retval;
retcode = pthread_create (&th_a, NULL, process, (void *) "a");
if (retcode != 0)
abort ();
retcode = pthread_create (&th_b, NULL, process, (void *) "b");
if (retcode != 0)
abort ();
retcode = pthread_join (th_a, &retval);
if (retcode != 0)
abort ();
retcode = pthread_join (th_b, &retval);
if (retcode != 0)
abort ();
printf ("pass\n");
return 0;
}