summaryrefslogtreecommitdiffstats
path: root/posix_api/psx_example_2/test2.c
blob: 499e899c0f4dd5584143fdc64fdfdc6d31177d29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <sys/time.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>

pthread_mutex_t mutex;
pthread_cond_t cond;

void * print_hello(void * arg)
{
  struct timeval time;
  struct timespec timeout;

  gettimeofday(&time, NULL);
  timeout.tv_sec = time.tv_sec + 2;
  timeout.tv_nsec = time.tv_usec * 1000;
  printf("<child>: Hello World coming to wait!\n");

  if (pthread_cond_timedwait(&cond, &mutex, &timeout))
   perror ("Error on pthread_cond_timedwait");

  printf("<child>: Hello World exit to wait!\n");
  return NULL;
}

void *POSIX_Init(void *arg)
{
  pthread_t child;
  if ( pthread_create( &child, NULL, print_hello, NULL ))
    perror("Error on pthread_create");
  printf("<main>: Wait for child thread...\n");
  if ( pthread_join( child, NULL ))
    perror("Error on pthread_join");
  return 0;
}

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_POSIX_THREADS              10
#define CONFIGURE_POSIX_INIT_THREAD_TABLE

#define CONFIGURE_INIT
#include <rtems/confdefs.h>