blob: 1916c37fbd322aa707d2fd1f8dc8f2e9f4b833c1 [file] [log] [blame]
sewardjb4112022007-11-09 22:49:28 +00001#include <pthread.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5/* Simple demonstration of lockset tracking at byte granularity. */
6
7char bytes[10];
8
9void* child_fn ( void* arg )
10{
11 int i;
12 for (i = 0; i < 5; i++)
13 bytes[2*i + 0] ++;
14 return NULL;
15}
16
17int main ( void )
18{
19 int i;
20 pthread_t child;
21
22 if (pthread_create(&child, NULL, child_fn, NULL)) {
23 perror("pthread_create");
24 exit(1);
25 }
26
27 /* Unprotected relative to child, but harmless, since different
28 bytes accessed */
29 for (i = 0; i < 5; i++)
30 bytes[2*i + 1] ++;
31
32 /* Unprotected relative to child, but harmful; same bytes */
33 for (i = 0; i < 3; i++)
34 bytes[3*i + 1] ++;
35
36 if (pthread_join(child, NULL)) {
37 perror("pthread join");
38 exit(1);
39 }
40
41 return 0;
42}