查看完整版本: [-- 多线程共享缓冲区问题,求解 --]

QTCN开发网 -> Qt基础编程 -> 多线程共享缓冲区问题,求解 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

shixingya 2018-03-09 18:21

多线程共享缓冲区问题,求解

在进程中,声明了static QList<MyStruct> cacheList ; 作为全局缓存结构

在主线程中会读取cacheList 中的数据

在n个子线程中 会修改cacheList 中的数据,

子线程run中 我通过QMutex加锁, 主线程用cacheList 的时候需要加锁吗?

hitler++ 2018-03-12 02:02
必须加锁

用 std::shared_mutex

读的时候 std::shared_lock<std::shared_mutex>(xxxx)

写的时候 std::unique_lock<std::shared_mutex>(xxxx)

shixingya 2018-03-12 09:45
hitler++:必须加锁
用 std::shared_mutex
读的时候 std::shared_lock<std::shared_mutex>(xxxx)
....... (2018-03-12 02:02) 

可是加锁 会导致速度变慢呀


查看完整版本: [-- 多线程共享缓冲区问题,求解 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled