当前位置:网站首页>Problems of CString in multithreading
Problems of CString in multithreading
2022-07-03 15:26:00 【Yulong_】
It's OK to be free , Chat CString Easy to step on in multithreading , This pit is likely to exist in your current project .
give an example :
int main()
{
CString str = L"test";
CString strThread1 = str;
CString strThread2 = str;
// Pass the two parameters to their respective threads , The following uses pseudo code
CThread thread1(strThread1);
CThread thread2(strThread2);
thread1.wait();
thread2.wait();
return 0;
}
Don't assume that strThread1 and strThread2 It's just a temporary variable , It's safe to pass values into threads ,CString The interior of the is more complex , Yes Such as reference count , When writing copy This function , in other words , In this code str、strThread1 as well as strThread2 It points to the same section of memory , stay The result of operating a section of memory in multithreading can be imagined , ha-ha !
When debugging the code, it can be proved that these three variables point to the same section of memory :
边栏推荐
- 使用Tengine解决负载均衡的Session问题
- 详解指针进阶2
- Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
- Seckill system 2 redis solves the problem of distributed session
- Markdown file titles are all reduced by one level
- XWiki Installation Tips
- 高并发下之redis锁优化实战
- WinDbg分析dump文件
- 【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
- Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock
猜你喜欢
Can‘t connect to MySQL server on ‘localhost‘
需要知道的字符串函数
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
Didi off the shelf! Data security is national security
Kubernetes带你从头到尾捋一遍
CString的GetBuffer和ReleaseBuffer使用说明
Digital image processing -- popular Canny edge detection
Tensorflow realizes verification code recognition (III)
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
随机推荐
函数栈帧的创建和销毁
Kubernetes带你从头到尾捋一遍
do{}while()的妙用
Functional modules and application scenarios covered by the productization of user portraits
求字符串函数和长度不受限制的字符串函数的详解
Calibre LVL
Jvm-06-execution engine
视觉上位系统设计开发(halcon-winform)-4.通信管理
The method of parameter estimation of user-defined function in MATLAB
需要知道的字符串函数
Detailed explanation of string function and string function with unlimited length
mysql innodb 存储引擎的特性—行锁剖析
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
Use of Tex editor
Visual upper system design and development (Halcon WinForm) -5 camera
Popular understanding of linear regression (I)
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
使用Tengine解决负载均衡的Session问题
使用JMeter对WebService进行压力测试
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project