Flow is not passing in a worker thread
-
I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance
-
I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance
Hey, You can use void sleep( long millis ) instead of using timer
Regards, Pankaj Sachdeva There is no future lies in any job but future lies in the person who holds the job
-
I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance
neha.agarwal27 wrote:
Now my problem is in some case a api is not passing the flow of control
do you mean that, your control flow is not coming out of your api? if that is so, then, as you said, timer is not working, you can initiate another thread and do your termination there after 10 seconds. any more clarifications?
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
neha.agarwal27 wrote:
Now my problem is in some case a api is not passing the flow of control
do you mean that, your control flow is not coming out of your api? if that is so, then, as you said, timer is not working, you can initiate another thread and do your termination there after 10 seconds. any more clarifications?
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
can you explain me this through an example. I am not getting where to start a thread and how to apply your procedure
-
can you explain me this through an example. I am not getting where to start a thread and how to apply your procedure
say your thread 1 is like this.
thread1 { .... .... .... .... api1(); .... .... .... }
if you feel that some times your control is not coming out of api1. right? so, take a global variable, say flag=0; before api1, make flag=1; and after api1 make it 0; take another thread, say,thread2() { int counter=0; while(1) { Sleep(1000);//1 second if(flag==1) { counter++; if(counter>10) terminate thread 1. } if (flag==0) { counter=0; } } } } }
neha.agarwal27 wrote:
I am not getting where to start a thread and how to apply your procedure
start it just after your main thread creation.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
say your thread 1 is like this.
thread1 { .... .... .... .... api1(); .... .... .... }
if you feel that some times your control is not coming out of api1. right? so, take a global variable, say flag=0; before api1, make flag=1; and after api1 make it 0; take another thread, say,thread2() { int counter=0; while(1) { Sleep(1000);//1 second if(flag==1) { counter++; if(counter>10) terminate thread 1. } if (flag==0) { counter=0; } } } } }
neha.agarwal27 wrote:
I am not getting where to start a thread and how to apply your procedure
start it just after your main thread creation.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.
-
your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.
yah, got your problem. then you must change your architecture, in such a way, that, the timeout monitor thread is not common for all the threads. so implement as follows. thread1()//this thread may be having somany instances { create thread2();//which monitors the thread 1 for the timeout value. ------- ------ -------- flag=1; api1; flag=0; -------- } thread2() { you try to frame this logic. } here, for each thread1, a child thread(thread2) is created, which monitors its parent's(thread1's) timeout, and kills it if it is not responding in a specified timeout, and also terminates itself.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.
-
got it?
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
i am still trying the method problem is not solved yet...