none
线程Thread->Sleep(-1)后程序出现假死现象 RRS feed

  • 问题

  • 如题,我编写的软件需要对线程进行暂停操作,可执行Thread->Sleep(-1)后程序出现假死现象,当Thread->Sleep(10)时只假死10秒钟,之后继续运行线程。求大牛解决
    2014年6月24日 11:31

答案

  • 你好,

    请问你是在处理多线程还是单线程?还有sleep 的参数是以毫秒计的。

    你当前的问题是属于线程假死问题,你可以考虑用异步调用技术去避免假死。以下关于C++异步的学习链接供你参考:

    http://www.cplusplus.com/reference/future/async/

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年7月4日 2:54

全部回复

  • 你好,

    当sleep的值为负数值时,线程将被冻结和锁定,看上去就像假死一样。所以最好在sleep 前对传入数值进行一下判定,例如:

    if(ms > 1)
    {
        Thread->Sleep(ms);
    }

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月25日 7:10
  • Thread->Sleep(10)也会被冻结和锁定10s,而且我想实现的是一直sleep,直到用户点击开始,就像迅雷一样
    2014年6月27日 10:51
  • 你好,

    请问你是在处理多线程还是单线程?还有sleep 的参数是以毫秒计的。

    你当前的问题是属于线程假死问题,你可以考虑用异步调用技术去避免假死。以下关于C++异步的学习链接供你参考:

    http://www.cplusplus.com/reference/future/async/

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年7月4日 2:54