I am pretty new to using C++ and I can't figure this out.
I have class PTM that starts a thread. There is an array of structure
to be shared between PTM class and thread function. For some reason,
string data gets lost when it gets to the thread function.
----------
in PTM.h
----------
using namespace std;
struct process_list{
string title;
int status;
int num_restart;
string comments;
};
-----------
in PTM.cpp
-----------
process_list global_process[10];
int process_num ;
PTM::PTM(){
loadConfig()
CreateThread(...,LPTHREAD_START_ROUTINE)watchdog,. ..);
}
PTM::loadConfig() {
for (int i =0; i < condition; i++) {
global_process[i].title= "gets data";
global_process[i].status = 0;
}
process_num = i;
}
//global function in the file scope watchdog
int watchdog() {
//print the global variables
for (int j =0 ; j < process_num; j++) {
printLog("%s has died", global_process[i].title;
}
}
I ran it thru debugger. It seems like watchdog() sees process_num(int
type) global variable. It also sees status, num_restart in
globa_process but not title or comment which are string type.
loadConfig seems to work fine too.
Any ideas, comments, help will be greatly appreciate.
Thanks in advance,
Seung