gpt4 book ai didi

multithreading - “lock”应用程序的UI线程是什么意思?

转载 作者:行者123 更新时间:2023-12-03 11:42:23 27 4
gpt4 key购买 nike

我正在使用flkt-rs crate设计GUI。我想知道“锁定”应用程序的UI线程是什么意思。这是否意味着没有CPU分配给该线程?您为什么要锁定UI线程?那么什么时候才想解锁呢?
另外,我看到fltk::app::lock()函数返回了一个结果,这意味着使用它可能存在一些问题。是什么导致您无法成功锁定UI线程?
fltk-rs docs锁定功能:

pub fn lock() -> Result<(), FltkError>

最佳答案

FLTK C++ documentation:

In a multithreaded program, drawing of widgets (in the main() thread) happens asynchronously to widgets being updated by worker threads, so no drawing can occur safely whilst a widget is being modified (and no widget should be modified whilst drawing is in progress).

FLTK supports multithreaded applications using a locking mechanism internally. This allows a worker thread to lock the rendering context, preventing any drawing from taking place, whilst it changes the value of its widget.


因此,您不会长时间锁定用户界面;足够的时间来安全地更新小部件的状态,然后再次对其进行解锁。

What could prevent you from succesfully locking the UI thread?


同一文档的下一段可能会解决此问题:

To incorporate the locking mechanism in the library, FLTK must be compiled with –enable-threads set during the configure process. IDE-based versions of FLTK are automatically compiled with the locking mechanism incorporated if possible. Since version 1.3, the configure script that builds the FLTK library also sets –enable-threads by default.


如果将应用程序编译为单线程,则锁定主线程将永久锁定整个应用程序。它没有明确说明,但是在这种情况下出现 FailedToLock错误似乎是合理的。
这种API感觉不太“使用rust ”,可能是这样,因为 fltk-rs crate 是C++库的薄包装。

关于multithreading - “lock”应用程序的UI线程是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65944979/

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