시스템 timer를 두개이상 쓰려고 하는데 하나만 작동하는 경우

cho's의 이미지

thread를 쓰려다가 정확하게 초당 제어하려고 시스템 timer를 쓰려고 합니다.
현재 하나의 timer만 실행시에는 정확하게 realtime으로 함수콜이 이루어집니다.
하지만 하나이상의 것을 실행시 그 이전의 timer가 작동하지 않습니다.
SIGALRM이 가면 뒤에 timer가 실행이되서 처음의 timer가 동작하지 않는것 같습니다. 어떻게하면 서로 다른 각각의 timer가 동작하도록 할수 있을까요?
제가 system timer는 처음 써봐서 잘 모르겠습니다.
도움 부탁드립니다. 그럼 즐프하세요.
추가적으로 SIGUSR1으로 설정시에는 매번 콜이 일어나지 조차도 않는군요.
흑흑흑...


#include <signal.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/unistd.h>

#define TRUE 1
#define FALSE 0

static sigset_t timer_alarm_mask;
static struct itimerval itimer_reqst, ovalue;
static struct sigaction siga;

static sigset_t timer_mask;
static struct itimerval itimer_req, value;
static struct sigaction sigact;

int cnt = 0;
int misccnt = 0;

static void every_sec_timer_proc(int v){
	cnt++;
	printf("%s called, %d\n", __func__, cnt);
}

static void every_misc_timer_proc(int v){
	misccnt++;
	printf("%s called, %d\n", __func__, misccnt);
}


void start_every_sec_timer()
{
	long mics_per_frame;

	printf("%s\n", __func__);
	//Set a signal handler for interval timer processing
	siga.sa_handler = every_sec_timer_proc;
	siga.sa_flags = SA_RESTART;
	siga.sa_mask = timer_alarm_mask;

        if( sigaction(SIGALRM, &siga, NULL) < 0){
	                return FALSE;
	}
        // initialize Posix Timer
	sigemptyset(&timer_alarm_mask);
	sigaddset(&timer_alarm_mask, SIGALRM | SIGRTMAX);
	
	// Set the initial delay and period of timer, this also arms timer.
	mics_per_frame = 10;
        itimer_reqst.it_interval.tv_sec = 0L;
        //usec is micro second
	//itimer_reqst.it_interval.tv_usec = (long)mics_per_frame;
	itimer_reqst.it_interval.tv_usec = (long)2000000;
	itimer_reqst.it_value.tv_sec = 0L;
	//itimer_reqst.it_value.tv_usec = (long)mics_per_frame;
	itimer_reqst.it_value.tv_usec = (long)2000000;
	if( setitimer(ITIMER_REAL, &itimer_reqst, &ovalue) < 0)
		return FALSE;
	return TRUE;

}

void stop_every_sec_timer()
{

	printf("%s\n", __func__);
        itimer_reqst.it_interval.tv_sec = 0L;
	itimer_reqst.it_interval.tv_usec = 0L;
	itimer_reqst.it_value.tv_sec = 0L;
	itimer_reqst.it_value.tv_usec = 0L;
	if( setitimer(ITIMER_REAL, &itimer_reqst, &ovalue) < 0)
		return FALSE;
	return TRUE;

}

void start_every_misc_timer()
{
	long mics_per_frame;

	printf("%s\n", __func__);
	//Set a signal handler for interval timer processing
	sigact.sa_handler = every_misc_timer_proc;
	sigact.sa_flags = SA_RESTART;
	sigact.sa_mask = timer_mask;

        if( sigaction(SIGALRM, &sigact, NULL) < 0){
	                return FALSE;
	}
        // initialize Posix Timer
	sigemptyset(&timer_mask);
	sigaddset(&timer_mask, SIGALRM | SIGRTMAX);
	
	// Set the initial delay and period of timer, this also arms timer.
        itimer_req.it_interval.tv_sec = 0L;
	itimer_req.it_interval.tv_usec = (long)10000;
	itimer_req.it_value.tv_sec = 0L;
	//itimer_req.it_value.tv_usec = (long)mics_per_frame;
	itimer_req.it_value.tv_usec = (long)10000;
	if( setitimer(ITIMER_REAL, &itimer_req, &value) < 0)
		return FALSE;
	return TRUE;

}

void stop_every_misc_timer()
{

	printf("%s\n", __func__);
        itimer_req.it_interval.tv_sec = 0L;
	itimer_req.it_interval.tv_usec = 0L;
	itimer_req.it_value.tv_sec = 0L;
	itimer_req.it_value.tv_usec = 0L;
	if( setitimer(ITIMER_REAL, &itimer_req, &value) < 0)
		return FALSE;
	return TRUE;

}


int main(int argc, char* argv[])
{
	int i;
	start_every_sec_timer();
	sleep(2);

	for(i = 0; i < 300000; i++) {
		char tmp2[100];
		strcpy(tmp2, "ksksk");
	}
	
	start_every_misc_timer();
	while(1){
		char tmp[100];
		strcpy(tmp, "calling testing");	

	}
	stop_every_sec_timer();


}
pynoos의 이미지

setitimer로 제어할 수 있는 timer는 프로세스당 한 개입니다.

대개 많은 OS가 그렇듯이 timer 라는 것은 제약적인 자원이라서 API도 자유자재로 timer resource를 주지 않고, 상당수 하나의 timer로 여러개 효과를 내야합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.