Can be accessed by reading shared variable
create new list element element set e.value = X read list and list.p_next set e.pointer = list.p_next set list.p_next = e
Mutex, Lock(mutex), blocked_threads
List<int> my_list; Mutex m; void safe_insert(int i){ Lock(m){ my_list.insert(i); } }
for i=0..10 producers[i] = fork(safe_insert, NULL) consumer = fork(print_and_clear, my_list) Lock(m){ list->insert(my_thread_id) } // unlock Lock(m){ if my_list.full -> print; clear up to limit of elements of list else -> release lock and try again (later) }
Condition Variable
Lock(m){ while (my_list.not_full()) Wait(m. list_full); m_list.print_and_remove_all(); } Lock(m){ my_list.insert(my_thread_id); if my_list.full() Signal(list_full); }