gpt4 book ai didi

multithreading - 线程安全是什么意思?

转载 作者:行者123 更新时间:2023-12-03 04:38:48 24 4
gpt4 key购买 nike

最近我尝试从线程(UI 线程除外)访问文本框,并抛出异常。它说了一些关于“代码不是线程安全的”,所以我最终编写了一个委托(delegate)(来自 MSDN 的示例有所帮助)并调用它。

但即便如此,我还是不太明白为什么所有额外的代码都是必要的。

更新:如果我检查,我会遇到任何严重问题

Controls.CheckForIllegalCrossThread..blah =true

最佳答案

Eric Lippert有一篇不错的博客文章,标题为What is this thing you call "thread safe"?关于维基百科中线程安全的定义。

从链接中提取的 3 个重要内容:

“A piece of code is thread-safe if it functions correctly duringsimultaneous execution by multiple threads.”

“In particular, it must satisfy the need for multiple threads toaccess the same shared data, …”

“…and the need for a shared piece of data to be accessed by only onethread at any given time.”

绝对值得一读!

关于multithreading - 线程安全是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2033879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com