在非VCL应用程序中使用同步是否有危险? [英] Is it dangerous to use synchronize in a non-VCL application?

查看:118
本文介绍了在非VCL应用程序中使用同步是否有危险?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Delphi代码是用同步编写来对主VCL线程进行序列化访问的,那么这个代码是否用在非VCL应用程序中,它是否与应用程序的主线程同步,或者根本没有效果?

If Delphi code was written with synchronize to serialize access to the main VCL thread, but this code then is used in a non-VCL application, will it synchronize with the main thread of the application or just have no effect at all?

示例:

procedure TMyThread.Execute;
begin

  // ... other code

  Synchronize(SomeMethod);

  // ...

end;

我们假设


  • 它是一个非VCL应用程序,它具有以无限循环(或直到终止)执行的主线程。

  • 主线程不调用 CheckSynchronize 直接或在WakeMainThread处理程序中

  • 辅助线程运行并执行同步(SomeMethod),如上例所示

挂在Synchronize(SomeMethod)行上?

Will the thread hang on the Synchronize(SomeMethod) line?

推荐答案

TThread 提供设施对于非VCL程序来检查同步队列,因此可以继续使用希望同步其方法的多线程库。这在 CheckSynchronize 。请记住,应用程序的工作是检查队列,而不是您的库。

TThread provides facilities for non-VCL programs to check the synchronization queue, so they can continue to use multithreaded libraries that expect to synchronize their methods. This is described in the documentation for CheckSynchronize. Remember that it's the application's job to check the queue, not your library's.

只要应用程序符合合同的一部分,您使用同步应该没关系然而,如果没有,那么你的程序将无法正常工作,但是我不知道要预期的确切症状。挂肯定听起来似乎合理。

As long as the application honors its part of the contract, your use of Synchronize should be fine. If it doesn't, though, then your program will not work correctly, but I don't know what exact symptoms to expect. Hanging certainly sounds plausible.

这篇关于在非VCL应用程序中使用同步是否有危险?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆