Kernel based execution time

Hello i want to solve a problem using many different seeds for the random number generator.
I need to run this program with a few hundred threads and each threads only needs an int N as parameter and can work 100% on its own(no shared data).
The Problem could be solved after any time from each thread and i want to end it as soon as one thread came to an solution.

How can i make something like this? so that all other threads stop as soon as one thread finished while knowing wich thread solved the problem/wich seed solved it.

Hope you can help me :D

Of course it will require inter-thread communication of some sort. One possible approach:

If the work process is cyclical in any way in each thread, you could have a volatile variable in global memory, perhaps initialized to -1, and during the cyclical processing each thread could read the value to see if another thread has found the solution (indicated by a value other than -1). If the solution is found, after reading the value, the thread terminates. If no solution is indicated, the thread continues its cyclical processing.

A thread which has found the solution will write it’s own globally unique thread index to the global value, perhaps with an atomicCAS operation to handle contention gracefully, if the algorithm has the possibility for multiple threads to find a solution.

At the conclusion of processing the global variable contains the ID of the thread which found the solution (first).