Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is this possible? Im so used to using the .NET stuff, that when im in C adding this Multithreading to an app i didnt even think about it.

Basically only one instance of this function seems to be able to be created.

I have function X in a seperate library that contains this function.
Each item that gets created creates a thread to that function.

Only one instance of that function ever gets run(the one that got created first).

Any ideas?
Posted
Comments
Anthony Mushrow 2-Mar-11 21:20pm    
I just did a quick check with CreateThread myself and everything works as expected, is your setup significantly different to this:

#include <windows.h>
DWORD WINAPI t_func(PVOID args){
printf("Threaded Write\n"); return 0;
}
int _tmain(int argc, _TCHAR* argv[]){
HANDLE Threads[5];
printf("Bacon\n");
for(int i=0; i<5; i++)
Threads[i] = CreateThread(NULL, 0, t_func, NULL, 0, NULL);
WaitForMultipleObjects(5, Threads, true, INFINITE);
return 0;
}
Output:
Bacon
Threaded Write
Threaded Write
Threaded Write
Threaded Write
Threaded Write

1 solution

This is quite possible. The same function runs in a separate thread, so each time the same code gets its separate stack, what's wrong with that?

It's quite hard to say why your code works only in one thread. There can be different reasons for that. I need to see you code sample to find out.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900