Kylix 中的 TEvent.WaitFor
在 Kylix 中,TEvent.WaitFor(Timeout) 方法仅接受 $FFFFFFFF 的超时,否则会生成错误。它在内部使用 sem_wait 函数,该函数没有超时参数。有什么办法解决这个问题吗?我需要设置一个超时参数。
In Kylix TEvent.WaitFor(Timeout) method only accepts Timeout of $FFFFFFFF, otherwise it generates an error. Internally it uses sem_wait function which doesn't have a timeout parameter. It there any way around this? I need to set a timeout parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
sem_timedwait 在 Linux 较旧的线程实现中(LinuxThreads,在 2.4 中引入 NPTL 之前)已被破坏。一些发行版仍然将 Kylix 可执行文件链接到那些较旧的库作为向后兼容性填充程序,因为 Kylix 不包含链接器期望的版本信息。 FreePascal 不存在此问题,因为它确实包含版本信息,因此它始终与较新的线程库链接。
我们通过轮询和睡眠来解决这个问题。它并不漂亮或高效,但它是 TEvent.WaitFor 的直接替代品:
sem_timedwait is broken in Linux's older thread implementations (LinuxThreads, prior to the introduction of NPTL in 2.4). Some distributions still link Kylix executables against those older libraries as backwards compatibility shims, because Kylix doesn't include version information the linker expects. FreePascal doesn't have this problem because it does include the version info, so it's always linked against the newer thread libraries.
We worked around the issue by polling and sleeping. It's not pretty or efficient, but it is a drop-in replacement for TEvent.WaitFor:
在 Google 上搜索“kylix tevent.waitfor”,您会看到有关该问题的各种帖子/讨论,至少可以追溯到 2002 年。我没有详细浏览过它们,但看起来像 http://www.mswil.ch/websvn/filedetails.php?repname=devphp&path=%2Fcomponent%2FIndy9%2FSource%2FIdHL7.pas&sc=1 有修复。
Search Google for "kylix tevent.waitfor" and you'll see various postings/discussions going back to at least 2002 regarding the problem. I haven't browsed them in detail, but it looks like http://www.mswil.ch/websvn/filedetails.php?repname=devphp&path=%2Fcomponent%2FIndy9%2FSource%2FIdHL7.pas&sc=1 has a fix.
我查看了 FPC 源代码,并使用了基于 pthread_cont_timedwait 的更新函数,
请参见例如 http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/unix/cthreads.pp?view=markup
大约第 750 行
(过程 intBasiceventwaitfor 和 intRTLEventWaitForTimeout 这些是各种 .waitfor 函数的原语)
可能这只是 Kylix 显示其年龄。
I've looked in the FPC source, and newer functions are used, based on pthread_cont_timedwait
See e.g. http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/unix/cthreads.pp?view=markup
around line 750
(procedure intBasiceventwaitfor and intRTLEventWaitForTimeout these are primitives for various .waitfor functions )
Probably this is simply Kylix showing its age.