没有CLR的替代线程睡眠 [英] alternative thread sleep without CLR

查看:89
本文介绍了没有CLR的替代线程睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel 2003(官方多线程支持之前)中编写了多线程Excel C API代码,该线程使线程在等待线程不忙时等待添加作业时进入休眠状态.但是,当我使用以下代码使线程进入睡眠状态时,似乎会出现内存错误

 boost :: this_thread :: sleep(boost :: posix_time :: milliseconds( 100 ))



有没有一种我可以利用的好选择,而不会像无限循环那样利用CPU?

请注意,由于不兼容问题,我无法直接在加载项中使用CLR.但是,我可以引用CLR dll,但我不希望引用.我发现混合CLR和BOOST有时会泄漏内存.

解决方案

WaitForSingleObject()可能是可行的选择,或者是WinAPI中的Sleep(). /blockquote>

I wrote multi-threaded Excel C API code in Excel 2003 (before official multi-threading support) that puts a thread to sleep while it waits for jobs to be added whenever the thread is not busy. However, I seem to get a memory error when I put the thread to sleep with the following code

boost::this_thread::sleep(boost::posix_time::milliseconds(100))



Is there a good alternative that I can utilize that won''t utilize the CPU like an infinite loop would?

Note that I cannot utilize CLR directly in my add-in due to incompatibility issues. I could however reference a CLR dll, but I would prefer not to. I''ve found mixing CLR and BOOST sometimes leaks memory.

解决方案

WaitForSingleObject() could be a viable alternative, or Sleep() that is in the WinAPI.


这篇关于没有CLR的替代线程睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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