gpt4 book ai didi

thread-safety - 这些线程安全吗?

转载 作者:行者123 更新时间:2023-12-04 15:15:51 29 4
gpt4 key购买 nike

我今天参加了面试,面试官问了我以下问题:

重入互斥线程安全吗?你能解释一下为什么吗?

我对并发编程比较陌生,无法回答..但我说......

互斥是线程安全的。但是重入不是,这就是我们有重入锁的原因。

面试官继续问下一个问题,但转到了不同的领域……我想我把这个问题搞砸了……

当他问我这个时,他希望我说什么?

最佳答案

正确答案应该是:

是的,它们是线程安全的实现。

重入

Writing code in such a way that it can be partially executed by one task, reentered by another task, and then resumed from the original task. This requires the saving of state information in variables local to each task, usually on its stack, instead of in static or global variables.

one example



互斥

Access to shared data is serialized using mechanisms that ensure only one thread reads or writes the shared data at any time. Great care is required if a piece of code accesses multiple shared pieces of data—problems include race conditions, deadlocks, livelocks, starvation, and various other ills enumerated in many operating systems textbooks.

one example

关于thread-safety - 这些线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3751685/

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