I have a number of threads that may call a single function, but I want to protect this function with a critical region such that if one thread is in the function all the others must wait for access.

Any ideas?