code works for 2 processes but not for 4 processes. I will debug this tomorrow. I think sth with synchronization is wrong.