0
我正在開發一個多線程服務器應用程序。 我有這樣的結構,我試圖傳遞給兩個線程:線程的內存問題
struct params{
SafeQueue<int> *mq;
Database *db;
};
class Server{
Server(Database *db){
DWORD sthread, ethread;
params *p;
p = new params;
p->db = db;
SafeQueue<int> *msgq = new SafeQueue<int>;
p->mq = msgq;
cout << "Address of params: " << p << endl;
cout << "Address of SafeQueue: " << msgq << endl;
cout << "Starting Server...\n";
CreateThread(NULL, 0, smtpReceiver, &p, 0, &sthread);
CreateThread(NULL, 0, mQueue, &p, 0, ðread);
}
}
DWORD WINAPI mailQueue(LPVOID lpParam){
params *p = (params *) lpParam;
SafeQueue<int> *msgQ = p->mq;
cout << "Address of params: " << p << endl;
cout << "Address of SafeQueue: " << msgQ << endl;
cout << "Queue thread started...\n";
}
現在我遇到的問題是指針SafeQueue在mailQueue線程具有PARAMS結構的地址...查看輸出:
Address of params: 0x23878
Address of SafeQueue: 0x212c8
Starting Server...
Address of params: 0x28fe60
Address of SafeQueue: 0x23878
Queue thread started...