If the decrement leaves threadcount at zero, we know that there are no threads running, so it's time to exit.
如果互斥量threadcount的值减小到了零,我们知道这时已经没有线程在运行了,该退出程序了。
2
One way would be to increment a variable every time a thread is created, and decrement it whenever a thread terminates. When it reaches zero again, close the whole process.