- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在阅读Grok The GIL在关于锁定的讨论中,有如下的表述。
So long as no thread holds a lock while it sleeps, does I/O, or some other GIL-dropping operation, you should use the coarsest, simplest locks possible. Other threads couldn't have run in parallel anyway.
它是在关于抢占式多任务处理的讨论之后出现的。当你有锁时,什么可以防止 GIL 被抢先丢弃?或者这不是该声明所指的内容?
最佳答案
我问了这篇文章的作者,它归结为因为等待外部操作而删除 GIL 与内部抢占之间的区别:https://opensource.com/article/17/4/grok-gil#comment-136186
Hi! Nothing prevents a thread from preemptively dropping the GIL whileit holds a lock. Let's call that Thread A, and let's say there's alsoa Thread B. If Thread A holds a lock and gets preempted, then maybeThread B could run instead of Thread A.
If Thread B is waiting for the lock that Thread A is holding, then Thread B is not waiting for the GIL. In that case Thread A reacquires the GIL immediately after dropping it, and Thread A continues.
If Thread B is not waiting forthe lock that Thread A is holding, then Thread B might acquire the GILand run.
My point about coarse locks, however, is this: no two threadscan ever execute Python in parallel, because of the GIL. So usingfine-grained locks doesn't improve throughput. This is in contrast toa language like Java or C, where fine-grained locks allow greaterparallelism, and therefore greater throughput.
我仍然需要一些澄清,他确实证实了这一点:
If I'm understanding you correctly, the intent of the statement I referenced was to avoid using locks around external operations, where you could then block multiple threads, if they all depended on that lock.
For the preemptive example, Thread A isn't blocked by anything externally, so the processing just goes back and forth similar to cooperative multitasking.
关于python - 了解使用锁和 Python GIL 的抢占式多任务处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44981958/
我写了一段代码,其中有一个数据: unsigned char buf[4096]; // data in chunks of size 4k unsigned counter[256]; 我将每 3
这个问题已经有答案了: Ajax too slow - Recursion (1 个回答) 已关闭 5 年前。 所以这件事在我脑海里思考了很长时间,是否 AJAx 中给出的计时器在它必须发送另一个请求
据我所知,在 Linux 中有许多机制可以实现 bottom-halves: 软中断 任务 工作队列 线程中断 ( request_threaded_irq() ) 它们在可调度性方面都有自己的特点。
根据这个问题here使用 pthread_spin_lock 锁定关键部分是危险的,因为线程可能会被调度程序中断,而其他线程可能会在该资源上保持旋转状态。 假设我决定从 pthread_spin_lo
从SLF4J页面我明白了这一点 The purpose of slf4j-log4j12 module is to delegate or redirect calls made to an SLF4
我在我的项目中使用了 xuggle library 将视频从 mp4 转码为 flv。我也使用 slf4j 库 来支持日志结束。 import com.xuggle.mediatool.IMediaR
我是一名优秀的程序员,十分优秀!