当前位置: 技术问答>linux和unix
sleep 的替代函数如何实现
来源: 互联网 发布时间:2015-08-19
本文导语: 由于在soliar下signal(SIGALRM,func) alarm(10)与sleep(10)有冲突,, 如何写个sleep的替代函数?? | 如果使用select的话,alarm也可以不使用的 而且一般来说使用sleep的话,进程应该处于挂起状态,不会使用CPU...
由于在soliar下signal(SIGALRM,func) alarm(10)与sleep(10)有冲突,,
如何写个sleep的替代函数??
如何写个sleep的替代函数??
|
如果使用select的话,alarm也可以不使用的
而且一般来说使用sleep的话,进程应该处于挂起状态,不会使用CPU过于忙碌.除非sleep经常出错,而你使用了一个循环不停地调用sleep
是不是Pro*C不能做SQL COMMIT? 打出错误原因来看看
而且一般来说使用sleep的话,进程应该处于挂起状态,不会使用CPU过于忙碌.除非sleep经常出错,而你使用了一个循环不停地调用sleep
是不是Pro*C不能做SQL COMMIT? 打出错误原因来看看
|
signal(SIGALRM,func) alarm(10)与sleep(10)有冲突?
干吗不将alarm(10)换为setitimer试试?
干吗不将alarm(10)换为setitimer试试?
|
用事件,waitforsingleobject,从1开始计数,到了指定时间再setevent
|
参见《UNIX环境高级编程》信号部分
以下是它里面的POSIX.1 sleep的可靠实现
#include
#include
#include "ourhdr.h"
static void
sig_alrm(void)
{
return; /* nothing to do, just returning wakes up sigsuspend() */
}
unsigned int
sleep(unsigned int nsecs)
{
struct sigaction newact, oldact;
sigset_t newmask, oldmask, suspmask;
unsigned int unslept;
newact.sa_handler = sig_alrm;
sigemptyset(&newact.sa_mask);
newact.sa_flags = 0;
sigaction(SIGALRM, &newact, &oldact);
/* set our handler, save previous information */
sigemptyset(&newmask);
sigaddset(&newmask, SIGALRM);
/* block SIGALRM and save current signal mask */
sigprocmask(SIG_BLOCK, &newmask, &oldmask);
alarm(nsecs);
suspmask = oldmask;
sigdelset(&suspmask, SIGALRM); /* make sure SIGALRM isn't blocked */
sigsuspend(&suspmask); /* wait for any signal to be caught */
/* some signal has been caught, SIGALRM is now blocked */
unslept = alarm(0);
sigaction(SIGALRM, &oldact, NULL); /* reset previous action */
/* reset signal mask, which unblocks SIGALRM */
sigprocmask(SIG_SETMASK, &oldmask, NULL);
return(unslept);
}
以下是它里面的POSIX.1 sleep的可靠实现
#include
#include
#include "ourhdr.h"
static void
sig_alrm(void)
{
return; /* nothing to do, just returning wakes up sigsuspend() */
}
unsigned int
sleep(unsigned int nsecs)
{
struct sigaction newact, oldact;
sigset_t newmask, oldmask, suspmask;
unsigned int unslept;
newact.sa_handler = sig_alrm;
sigemptyset(&newact.sa_mask);
newact.sa_flags = 0;
sigaction(SIGALRM, &newact, &oldact);
/* set our handler, save previous information */
sigemptyset(&newmask);
sigaddset(&newmask, SIGALRM);
/* block SIGALRM and save current signal mask */
sigprocmask(SIG_BLOCK, &newmask, &oldmask);
alarm(nsecs);
suspmask = oldmask;
sigdelset(&suspmask, SIGALRM); /* make sure SIGALRM isn't blocked */
sigsuspend(&suspmask); /* wait for any signal to be caught */
/* some signal has been caught, SIGALRM is now blocked */
unslept = alarm(0);
sigaction(SIGALRM, &oldact, NULL); /* reset previous action */
/* reset signal mask, which unblocks SIGALRM */
sigprocmask(SIG_SETMASK, &oldmask, NULL);
return(unslept);
}
|
sleep可能是用SIGALRM实现的,所以不能混用。
proc不能commit是什么意思???
proc不能commit是什么意思???