CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  进程/线程/DLL

vc中Sleep函数的问题?

楼主dongterry(terry)2004-09-03 18:51:13 在 VC/MFC / 进程/线程/DLL 提问

我用Sleep做主程序中等,在Sleep前面我开了一个线程。为什么在Sleep的过程中,线程也不干活了??为什么?如果让线程干活,主程序等,用什么方法实现?  
  问题点数:0、回复次数:6Top

1 楼danscort2000(danscort.yu)回复于 2004-09-03 21:41:23 得分 0

问题不清楚,  
  是工作者线程还是界面线程?  
  初始化线程的时候是否挂起还是立即运行?  
  有没有同步变量控制全局变量?  
  是否消息死锁?  
  ......Top

2 楼flyelf(空谷清音)回复于 2004-09-03 22:34:25 得分 0

是否在创建线程的时候用了暂停的标志?Top

3 楼mahatma_cn(研究硕士生)回复于 2004-09-03 23:08:21 得分 0

怪问题,没有特殊原因的话,他应该会干活的。Top

4 楼kugou123(酷狗)(彪悍的人生,不需要解释 www.xiaozhou.net)回复于 2004-09-03 23:21:43 得分 0

用WaitForSingleObject();  
   
  DWORD   WaitForSingleObject(  
      HANDLE   hHandle,  
      DWORD   dwMilliseconds  
  );  
   
  Parameters  
  hHandle    
  [in]   Handle   to   the   object.   For   a   list   of   the   object   types   whose   handles   can   be   specified,   see   the   following   Remarks   section.    
  If   this   handle   is   closed   while   the   wait   is   still   pending,   the   function's   behavior   is   undefined.  
   
  The   handle   must   have   the   SYNCHRONIZE   access   right.   For   more   information,   see   Standard   Access   Rights.  
   
  dwMilliseconds    
  [in]   Time-out   interval,   in   milliseconds.   The   function   returns   if   the   interval   elapses,   even   if   the   object's   state   is   nonsignaled.   If   dwMilliseconds   is   zero,   the   function   tests   the   object's   state   and   returns   immediately.   If   dwMilliseconds   is   INFINITE,   the   function's   time-out   interval   never   elapses.    
  Return   Values  
  If   the   function   succeeds,   the   return   value   indicates   the   event   that   caused   the   function   to   return.   It   can   be   one   of   the   following   values.  
   
  Return   Code   Description:  
   
  WAIT_ABANDONED   The   specified   object   is   a   mutex   object   that   was   not   released   by   the   thread   that   owned   the   mutex   object   before   the   owning   thread   terminated.   Ownership   of   the   mutex   object   is   granted   to   the   calling   thread,   and   the   mutex   is   set   to   nonsignaled.    
   
  WAIT_OBJECT_0   The   state   of   the   specified   object   is   signaled.    
   
  WAIT_TIMEOUT   The   time-out   interval   elapsed,   and   the   object's   state   is   nonsignaled.    
  Top

5 楼dansin(平平淡淡才是真)回复于 2004-09-05 10:55:13 得分 0

reference   by   MSDN..  
   
  You   have   to   be   careful   when   using   Sleep   and   code   that   directly   or   indirectly   creates   windows.   If   a   thread   creates   any   windows,   it   must   process   messages.   Message   broadcasts   are   sent   to   all   windows   in   the   system.   If   you   have   a   thread   that   uses   Sleep   with   infinite   delay,   the   system   will   deadlock.Top

6 楼allenq(黑夜给我黑的眼, 我却用他来翻白眼..........)回复于 2004-09-05 12:17:53 得分 0

在主线程中,尽量不要用Sleep去等待啊..  
  可能就是你的工作线程创建后是挂起状态的,  
   
  一般设置一个全局的同步变量,   主线程再另外开启一个线程,去检测这个同步变量的值变化以确定工作线程是否完成  
  Top

相关问题

  • VC中如何使用sleep()函数?
  • 关于VC中的函数
  • 在VC中用Sleep()函数之后,为什么程序变得很慢??
  • vc++库函数.
  • VC 6.0中有没有计算bessel函数的系统函数
  • 关于VC引用matlab6.5函数库中mlfGamma函数的方法()
  • Why?VC中会有回调函数?
  • 关于VC中的随机函数...
  • vc中有全局函数吗?????
  • VC中函数指针的使用

关键词

  • 线程
  • sleep
  • dwmilliseconds
  • 同步变量
  • nonsignaled
  • 干活
  • elapsed
  • mutex
  • 问题
  • wait

得分解答快速导航

  • 帖主:dongterry

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo