| 10 |
#include <stdio.h> |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
#include <stdlib.h> |
| 12 |
#include <string.h> |
#include <string.h> |
| 13 |
|
#include <time.h> |
| 14 |
#include <unistd.h> |
#include <unistd.h> |
| 15 |
|
|
| 16 |
#if __STDC_VERSION__ >= 201112L |
#if __STDC_VERSION__ >= 201112L |
| 42 |
atexit(visResultater); |
atexit(visResultater); |
| 43 |
signal(SIGINT, signalhandler); |
signal(SIGINT, signalhandler); |
| 44 |
|
|
| 45 |
|
#ifdef __FreeBSD__ |
| 46 |
srandomdev(); |
srandomdev(); |
| 47 |
|
#else |
| 48 |
|
srandom((unsigned int)time(NULL)); |
| 49 |
|
#endif |
| 50 |
|
|
| 51 |
memset((void *)&antallBesok, 0, sizeof(antallBesok)); |
memset((void *)&antallBesok, 0, sizeof(antallBesok)); |
| 52 |
brytere[0] = random() & 1; |
brytere[0] = random() & 1; |
| 66 |
printf("maintrĂ¥den oppretter livstidsfange %2zu\n", i + 1); |
printf("maintrĂ¥den oppretter livstidsfange %2zu\n", i + 1); |
| 67 |
|
|
| 68 |
if ( (errno = pthread_create(&tid, NULL, livstidsfange, (void *)i)) != 0) { |
if ( (errno = pthread_create(&tid, NULL, livstidsfange, (void *)i)) != 0) { |
| 69 |
|
fflush(stdout); |
| 70 |
fprintf(stderr, |
fprintf(stderr, |
| 71 |
"%s: pthread_create(&tid, NULL, livstidsfange, (void *)%2zu) = %s (%d)\n", |
"%s: pthread_create(&tid, NULL, livstidsfange, (void *)%2zu) = %s (%d)\n", |
| 72 |
argv[0], i, strerror(errno), errno); |
argv[0], i, strerror(errno), errno); |
| 73 |
exit(1); |
fflush(stderr); |
| 74 |
|
_exit(1); |
| 75 |
} // if |
} // if |
| 76 |
} // for |
} // for |
| 77 |
|
|
| 180 |
|
|
| 181 |
fflush(stderr); |
fflush(stderr); |
| 182 |
fflush(stdout); |
fflush(stdout); |
| 183 |
fflush(stderr); |
|
|
fflush(stdout); |
|
| 184 |
puts("\nResultater:\n"); |
puts("\nResultater:\n"); |
| 185 |
|
|
| 186 |
printf("bryter %u er ved avslutning vippet %s\n", 1U, brytere[0] == true ? "opp" : "ned"); |
printf("bryter %u er ved avslutning vippet %s\n", 1U, brytere[0] == true ? "opp" : "ned"); |