Click to See Complete Forum and Search --> : Combining 2 threaded programs
novice123
February 27th, 2006, 10:29 AM
Hi,
I have 2 separate threaded programs, now. I want to combine them into one single application.
If someone has done this before, can you please throw some light.
thank you
Siddhartha
February 27th, 2006, 01:56 PM
I have 2 separate threaded programs, now. I want to combine them into one single application. Combine them only if you have to...
(It is possible to synchronize activity across Processes (and threads within them), using Inter-Process Synchronization Objects - say like Named Mutexes.)
novice123
February 27th, 2006, 02:44 PM
Hi Sid,
Thank you for your response. But what i have is 2 separately running programs. I want to combine these under one main program. What i can say is there is no sharing of any data. Each of the program themselves have
2 threads and their data access is synchronized.
Please let me know
thank you
Siddhartha
February 27th, 2006, 02:51 PM
But what i have is 2 separately running programs. I want to combine these under one main program. What i can say is there is no sharing of any data....As no data is shared, there is no complication - right?
It is just a question of merging code correctly, and invoking the right method at the right place.
Arjay
February 27th, 2006, 03:16 PM
No sharing of data makes the merge process slightly easier, one thing to consider is whether the functionality from each of the separate programs are related or have dependencies on one another. Also, do you need to be able to invoke the functionalities independently. If so, consider putting the functionality into separate threads ( separate from the UI thread). That way, the UI can be in complete control of each [former] process's functionality.
Arjay
novice123
February 27th, 2006, 04:36 PM
Hi Sid, Arjay
Thanks for your response.
What i have done in Main , i have created 2 threads for each program
hThread1 = CreateThread(NULL,0,
(LP_THREAD_START_ROUTINE) ThreadFunc1,
&dwThrdParam,
0,
&dwThreadId1);
hThread2 = CreateThread(NULL,0,
(LP_THREAD_START_ROUTINE) ThreadFunc2,
&dwThrdParam,
0,
&dwThreadId2);
Handle h[] = {hThread1,hThread2};
WaitForMultipleObjects(2,h,TRUE,INFINITE);
Please let me if this is a correct approach.
Thanks again
kirants
February 27th, 2006, 05:10 PM
Seems ok, as long as that is the way you want i.e. you want to spawn 2 threads, and wait for both of them to finish before proceeding to do anything else.
Arjay
February 27th, 2006, 05:24 PM
Please let me if this is a correct approach. Thanks againSeems okay providing the main thread isn't a UI thread. Is your app a console app?
Arjay
kirants
February 27th, 2006, 05:28 PM
BTW, is it really needed that 2 threads be spawned for what you are doing ? I mean, is it an option for you to just invoke the functions that the threads do serially, one after another ? If it is, consider doing that.
novice123
March 17th, 2006, 09:34 AM
Hi All,
Thank you for your previous. I successfully integrated both the thread in one main program. Currently i am using CreateThread. Right now it is a command line console application. The only way to terminate the program is using cntrl c. I guess this is not good.
I want to change it to system tray-icon with options to start and stop. I followed the link provided by Siddarth for tray icons. I am able to start the thread, but having problems with the beavhiour. I am unable to stop the program. The first question is do i need to change from CreateThread to AfxBeginThread since i will be developing a system tray icon ?
can you please throw some light.
thank you
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.