Colleagues, welcome.
I have a program that synchronizes 3 threads with semaphores. But there is a problem that is presented in the picture.
It feels as if, after the completion of the program, the threads have not yet been fully implemented and continue to be executed.
Code listing on gist: https://gist.github.com/ArtemTellur/d7af7dfc4c4dcf08bb396b98345a248a
Please explain whether this is normal behavior. If not, what could be the error?
Thank you in advance!

printf? - ߊߚߤߘfflush()after each printf to buffered output - Mike