One can stop a thread by using pthread_join()
. But let's imagine one's got many threads that perform a complicated task and may not stop at the same time. One of them may stop earlier (because it's got the needed result). But how to stop other threads which can be almost infinite? If one thread's found the right solution, there is no more left, so other threads will never succeed.
How to terminate all threads when one of them got the result and stopped?