summaryrefslogtreecommitdiff
path: root/tests/mutex2.c
blob: cfbebdce9700a5f8c0c7f5e47ca80067c6ae5303 (plain)
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
/* 
 * mutex1.c
 *
 * Declare a static mutex object, lock it, and then unlock it again.
 */

#include <pthread.h>
#include "test.h"
 
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;

main()
{
  int result;

  result = pthread_mutex_trylock(&mutex1);
  printf("pthread_mutex_trylock returned %s\n", error_string[result]);
  if (result != 0)
    {
      return 1;
    }

  if (pthread_mutex_unlock(&mutex1) != 0)
    {
      return 1;
    }

  return 0;
}