1 |
// Programmet bruker ISO C 2011 (ISO/IEC 9899:2011) og Pthreads (IEEE Std 1003.1c-1995). -*- coding: utf-8 -*- |
// Programmet bruker ISO C 2011 (ISO/IEC 9899:2011) og Pthreads (IEEE Std 1003.1c-2001). -*- coding: utf-8 -*- |
2 |
// Løsning programmert av Trond Endrestøl <Trond.Endrestol@ximalas.info>, 2014-11-06. |
// Løsning programmert av Trond Endrestøl <Trond.Endrestol@ximalas.info>, 2014-11-06. |
3 |
|
|
4 |
// $Ximalas$ |
// $Ximalas$ |
5 |
|
|
6 |
#if __STDC_VERSION__ < 199901L |
#if __STDC_VERSION__ < 199901L |
7 |
#error det er tvilsomt om du får kompilert denne kildekoden med så gammel C-kompilator |
#error det er tvilsomt om du får kompilert denne kildekoden med så gammel C-kompilator |
8 |
#endif |
#endif |
9 |
|
|
10 |
#include <errno.h> |
#include <errno.h> |
11 |
#include <pthread.h> |
#include <pthread.h> |
12 |
#include <signal.h> |
#include <signal.h> |
13 |
#include <stdbool.h> |
#include <stdbool.h> |
14 |
#include <stdio.h> |
#include <stdio.h> |
15 |
#include <stdlib.h> |
#include <stdlib.h> |
16 |
#include <string.h> |
#include <string.h> |
17 |
#include <time.h> |
#include <time.h> |
18 |
#include <unistd.h> |
#include <unistd.h> |
19 |
|
|
20 |
|
#if _POSIX_THREADS < 200112L |
21 |
|
#error her mangler det støtte for POSIX Threads anno 2001 |
22 |
|
#endif |
23 |
|
|
24 |
#if __STDC_VERSION__ >= 201112L |
#if __STDC_VERSION__ >= 201112L |
25 |
#include <stdnoreturn.h> |
#include <stdnoreturn.h> |
26 |
#else |
#else |
27 |
#define noreturn |
#define noreturn |
28 |
#endif |
#endif |
29 |
|
|
30 |
#define ANTALL_LIVSTIDSFANGER 19U |
#define ANTALL_LIVSTIDSFANGER 19U |
31 |
|
|
32 |
static unsigned antallBesok[ANTALL_LIVSTIDSFANGER]; |
static unsigned antallBesok[ANTALL_LIVSTIDSFANGER]; |
33 |
|
|
34 |
static size_t tellendeLivstidsfange; |
static size_t tellendeLivstidsfange; |
35 |
static unsigned antallLivstidsfanger; |
static unsigned antallLivstidsfanger; |
36 |
|
|
37 |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |