I've done like you said but there is no improvement.
That is because it is still possible for the printer to print "BBB", send the notification, release the lock, and then grab it back, repeat.
Sending the notification does not give the lock to the waiting thread. The printer can hold (release and regrab) onto the lock sending many notifications before the waiting thread gets it.
Additionally, the main thread does not die (it doesn't print 'Program complete').
This is caused by a race condition between setting the flag and the sync lock -- as it is possible for the waiting thread to get the lock between those two actions.
ie. --> Notification is sent. --> notification is recieved --> message is printed --> while loop checks for flag --> thread waits --> then the flag is set.
Henry
[ September 24, 2008: Message edited by: Henry Wong ]