当前位置:网站首页>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 :
边栏推荐
- 在MapReduce中利用MultipleOutputs输出多个文件
- 如何使用 @NotNull等注解校验 并全局异常处理
- UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
- Kubernetes advanced training camp pod Foundation
- Chapter 04_ Logical architecture
- 自定义注解
- Final review points of human-computer interaction
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- Jvm-04-runtime data area heap, method area
- What is machine reading comprehension? What are the applications? Finally someone made it clear
猜你喜欢
Chapter 04_ Logical architecture
Idea does not specify an output path for the module
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
What is machine reading comprehension? What are the applications? Finally someone made it clear
[probably the most complete in Chinese] pushgateway entry notes
Jvm-04-runtime data area heap, method area
Solve the problem that pushgateway data will be overwritten by multiple push
How to use annotations such as @notnull to verify and handle global exceptions
mysql innodb 存储引擎的特性—行锁剖析
Summary of concurrent full knowledge points
随机推荐
使用JMeter对WebService进行压力测试
Popular understanding of linear regression (II)
Visual upper system design and development (Halcon WinForm) -4 Communication management
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Visual upper system design and development (Halcon WinForm) -2 Global variable design
Enable multi-threaded download of chrome and edge browsers
Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
Didi off the shelf! Data security is national security
如何使用 @NotNull等注解校验 并全局异常处理
Introduction to redis master-slave, sentinel and cluster mode
Jvm-08-garbage collector
Matplotlib drawing label cannot display Chinese problems
Kubernetes带你从头到尾捋一遍
CString在多线程中的问题
socket.io搭建分布式Web推送服务器
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
QT use qzxing to generate QR code
Using multipleoutputs to output multiple files in MapReduce
高并发下之redis锁优化实战