Hundreds of threads waiting on the same resource sound a bit . . . dodgy, but regardless:
using a lock and bool like this:
volatile bool exit = false;
void WorkerFunc()
{
lock(something)
{
if (exit)
return;
}
}
will cause the threads to wake up serially and die one at a time as each one acquires/releases the lock.
With the use of a Mutex and ManualResetEvent then each thread can use WaitForMultipleObjects and wait for both objects. If the mutex is signaled then the thread can access the resource, else if the event is signaled the thread knows to exit instead. The wakeup and die can be done in parallel (although that's one impressive machine that can physically wake up hundreds of threads all at once). Then the single line of code to kill all threads would be a simple setting of the shutdown event.