
Threaded, Embedded — Dreaded 187
40 /************************************************
41 * process_2 -- Second process of two. *
42 * *
43 * Grab both resources and then do the work. *
44 * (but slightly different work from *
45 * process_1) *
46 ************************************************/
47 static void process_2(void)
48 {
49 while (1) {
50 wait_for_work();
51
52 pthread_mutex_lock(&resource2);
53 pthread_mutex_lock(&resource1);
54
55 do_work();
56
57 pthread_mutex_unlock(&resource1);
58 pthread_mutex_unlock(&resource2);
59 }
60 }
61
62 int main()
63 {
64 int status; /* Status of last system call */
65
66 /* Information on the status thread */
67 pthread_t thread ...