Click here to Skip to main content
15,918,168 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to get the width & height of MPEG files with DirectX SDK? Pin
Hamid_RT11-May-07 0:42
Hamid_RT11-May-07 0:42 
GeneralRe: How to get the width & height of MPEG files with DirectX SDK? Pin
raytracingx13-May-07 16:08
raytracingx13-May-07 16:08 
QuestionApplication Data Directories Pin
Richard Andrew x6410-May-07 18:02
professionalRichard Andrew x6410-May-07 18:02 
QuestionThread parameter use same value for all thread ????? Pin
amitmistry_petlad 10-May-07 17:55
amitmistry_petlad 10-May-07 17:55 
AnswerRe: Thread parameter use same value for all thread ????? Pin
Arman S.10-May-07 20:40
Arman S.10-May-07 20:40 
GeneralRe: Thread parameter use same value for all thread ????? Pin
amitmistry_petlad 10-May-07 21:10
amitmistry_petlad 10-May-07 21:10 
GeneralRe: Thread parameter use same value for all thread ????? Pin
Arman S.11-May-07 0:13
Arman S.11-May-07 0:13 
GeneralRe: Thread parameter use same value for all thread ????? Pin
Arman S.11-May-07 1:01
Arman S.11-May-07 1:01 
Well. Your code has lots of things to recorrect. Though the abnormal behavior you described I could hardly connect to them. Let's start from general issues.

1) Are you using C and not C++?

2) Never use _beginthread! Use _beginthreadex instead. The first one is problematic and may cause hard-to-recognize errors! Your call should be;
<br />
unsigned int tid; // thread id<br />
hHandle[j] = (HANDLE ) _beginthreadex(NULL, 0, &Thread, l, 0, &tid);


3) Never use _endthreadex (nor use _endthread). These functions are mainly for urgent termination situations which are not inherent [normal] in a well designed architecture. Instead do 'return 0;'.

4) You should change the declaration form of Thread function; unsigned int should be returned to indicate the exit code. Now it should be;
UINT Thread(void *pArgs)

5) Are you sure your values are different inside the thread creation 'for' loop? Anyway, going on..

6) If your in C++, use new rather than malloc [but I thing you are in C].

7) Strings are erroneous! Remember that in a multithreaded application YOU SHOULD BE VERY VERY CAREFUL WHEN PASSING STRINGS INTO DIFFERENT THREADS!
So your code is wrong. YOU SHOULD CREATE SEPARATE STRING BUFFERS PER THREAD. That is;

for(int i=0;i<2;i++)
{
	struct argument_list *l = (argument_list *) malloc(sizeof(argument_list));
...

l->Host = (LPTSTR)malloc(MAX_PATH); // this kind of allocations should be for all strings of argument_list
	strcpy(l->Host, HOST);
...



8) To have a solid test inside Thread function also pass the j (loop index) to them; I mean add an extra int field to argument_list and observe its value from each thread function. They all should be different.

9) And one thing about Thread again. Never do such things;
//WaitForSingleObject(GetCurrentThread(),5000);
This makes no sense.



Finally, see what you can get from these notes. Take into consideretion each of them. Then I think you will overcome your problem.

You could tell me when you do smth. Smile | :)



--
=====
Arman

GeneralRe: Thread parameter use same value for all thread ????? Pin
amitmistry_petlad 11-May-07 1:15
amitmistry_petlad 11-May-07 1:15 
GeneralRe: Thread parameter use same value for all thread ????? Pin
Arman S.11-May-07 1:44
Arman S.11-May-07 1:44 
GeneralRe: Thread parameter use same value for all thread ????? Pin
Arman S.11-May-07 2:52
Arman S.11-May-07 2:52 
GeneralRe: Thread parameter use same value for all thread ????? Pin
amitmistry_petlad 13-May-07 19:24
amitmistry_petlad 13-May-07 19:24 
GeneralRe: Thread parameter use same value for all thread ????? Pin
amitmistry_petlad 16-May-07 22:55
amitmistry_petlad 16-May-07 22:55 
AnswerRe: Thread parameter use same value for all thread ????? Pin
ThatsAlok17-May-07 1:54
ThatsAlok17-May-07 1:54 
QuestionHow does a MFC process communicate with a .NET process? Pin
talihsu10-May-07 17:08
talihsu10-May-07 17:08 
AnswerRe: How does a MFC process communicate with a .NET process? Pin
led mike10-May-07 18:50
led mike10-May-07 18:50 
GeneralRe: How does a MFC process communicate with a .NET process? Pin
Mark Salsbery11-May-07 6:03
Mark Salsbery11-May-07 6:03 
QuestionRe: How does a MFC process communicate with a .NET process? Pin
Mark Salsbery11-May-07 6:04
Mark Salsbery11-May-07 6:04 
AnswerRe: How does a MFC process communicate with a .NET process? Pin
talihsu13-May-07 7:39
talihsu13-May-07 7:39 
GeneralRe: How does a MFC process communicate with a .NET process? Pin
Mark Salsbery14-May-07 3:50
Mark Salsbery14-May-07 3:50 
GeneralRe: How does a MFC process communicate with a .NET process? Pin
ThatsAlok16-May-07 22:41
ThatsAlok16-May-07 22:41 
QuestionShow drop selection in combobox Pin
amyvt10-May-07 16:35
amyvt10-May-07 16:35 
QuestionBooks and tools for a C newbie Pin
martin_hughes10-May-07 8:53
martin_hughes10-May-07 8:53 
AnswerRe: Books and tools for a C newbie Pin
Reagan Conservative10-May-07 10:09
Reagan Conservative10-May-07 10:09 
GeneralRe: Books and tools for a C newbie Pin
Stephen Hewitt10-May-07 16:27
Stephen Hewitt10-May-07 16:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.