【发布时间】:2011-01-15 13:18:36
【问题描述】:
最近听说栈内存不与其他线程共享,堆内存与其他线程共享。
我通常这样做:
HWND otherThreadHwnd;
DWORD commandId;
// initialize commandId and otherThreadHwnd
struct MyData {
int data1_;
long data2_;
void* chunk_;
};
int abc() {
MyData myData;
// initialize myData
SendMessage(otherThreadHwnd,commandId,&myData);
// read myData
}
这样可以吗?
【问题讨论】:
-
内存没问题。然而,死锁是可能的。如果调用线程本身泵送消息循环,则会出现令人讨厌的重入问题。考虑 SendMessageTimeout()。
标签: c++ windows-mobile memory-management dynamic-memory-allocation