Question: I have the following code which initiate the thread.

```
int iNMHandleThread = 1;
HANDLE hNMHandle = 0;
hNMHandle = CreateThread( NULL, 0, NMHandle, &iNMHandleThread, 0, NULL);
if ( hNMHandle == NULL)
ExitProcess(iNMHandleThread);

```

My question is

1. What will happened if I run this code while the thread already in the running state.
2. I want to initiate the multiple independent threads of NMHandle kindly give me some hints to solve this problem.

Answer: 
Each time you call `CreateThread`, a new thread is started that is independent of any other currently-running threads. Whether your "NMHandle" function is capable of running on more than one thread at a time is up to you: for example, does it rely on any global state?
1. CreateThread creates a new thread. The new thread obviously can't be in the running state before - it doesn't *have* a state before it's created. Compare the simple statement `int i = 42;` - There's no prior value of i before 42, because the object doesn't exist yet. Obviously the old thread that calls `CreateThread()` must be running - otherwise it couldn't have run to the line that calls `CreateThread()` !
2. Every time you call CreateThread, you will get a new thread. You will also get a new thread handle and ID for every call. So you can't store them all in `int iNMHandleThread` or `HANDLE hNMHandle`. Consider a `std::list<int> NmThreadIDs` and `std::list<HANDLE> NmThreadHandles;`.

Furthermore, all new threads will start by calling `NMHandle()`. Is that function thread-safe? That is to say, will that function work properly when executed by two threads at the same time, or interleaved, or in any other random order? Mechanisms like mutexes and critical sections can be used to exclude some unsafe orders of execution.