setitimer

setitimer question

ぃ、小莉子 提交于 2019-12-12 12:10:02
问题 I have the following code running on my dual core machine. When i'm running one or two instances of the application on the same PC, I have the correct timing resolution of 100msec. However, when i ran 3 instances of the same application on the same PC, the timing resolution is more than 100msec. Is it possible at all to make the 3 instances of application to run with the same resolution of 100msec? Is this related to the number of cores on my machine? #include <signal.h> #include <stdio.h>

Linux下定时器的使用

倖福魔咒の 提交于 2019-11-27 08:02:01
Linux下应用层定时器本来有好几种,大伙可以去搜索其他帖子博客,这里我主要描述我在使用setitimer时候遇到的问题,话不多说,直接上代码吧 例子一:只有定时器任务,为模拟复杂,我特意加个锁操作 // lock_timmer_test.cpp #include <iostream> #include <sys/time.h> #include <signal.h> #include <linux/types.h> #include <sched.h> #include <pthread.h> using namespace std; //互斥锁 class MutexLock { public: MutexLock(){ pthread_mutex_init(&m_stMutex, NULL); } ~MutexLock(){ pthread_mutex_destroy(&m_stMutex); } void lock(){ pthread_mutex_lock(&m_stMutex);} int unlock() {return pthread_mutex_unlock(&m_stMutex); } bool trylock(){ return pthread_mutex_trylock(&m_stMutex) == 0;} pthread_mutex_t*