我对C ++中的多线程有疑问。这是我第一次使用回调。如果他们是愚蠢的问题,请原谅我。
假设我有两个类,一个是缓存,另一个是使用缓存。
class Cache
{
public:
Refresh(){do something with _myCache}
private:
std::map<...> _myCache;
}
//Then I have another Class
class Processor
{
public:
Processor(){
bindToAThread(Cache::Refresh());
put it into a threadpool
}
private:
Cache cache;
}
原谅我的语法。
我的朋友告诉我,当Refresh()运行时,它将在_myCache的同一副本上运行到主线程。
我不太明白。子线程可以访问其父线程的堆栈吗?我认为同一进程中的线程只共享堆而不是堆栈。
有谁能告诉我为什么?
如果没有,有人可以告诉我该怎么办?启动子线程以修改主线程中的内容。
非常感谢!!