Thank you.I have understand part of them.
Is you mean
The second case you list is we wanted usually.
The first case (use sleep or join...)the result is wrong,they can't get the "totol=",is that means in the case that notify exec before wait will be dangerous,this programme would be frozen for ever?
If this case will happen possibly ,how to prevent it?