亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2531 | 回復(fù): 4
打印 上一主題 下一主題

計算延時不用考慮 時鐘調(diào)整和休眠? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-02-16 13:26 |只看該作者 |倒序瀏覽
誤人子弟啊,這些所謂的權(quán)威。。。
都是狗屁代碼

sun的
http://docs.sun.com/app/docs/doc ... pai?l=zh&a=view

  1. pthread_mutex_lock(&m);
  2. to.tv_sec = time(NULL) + TIMEOUT;
  3. to.tv_nsec = 0;
  4. while (cond == FALSE) {
  5.     err = pthread_cond_timedwait(&c, &m, &to);
  6.     if (err == ETIMEDOUT) {
  7.         /* timeout, do something */
  8.         break;
  9.     }
  10. }
  11. pthread_mutex_unlock(&m);
復(fù)制代碼


好像是man里的
http://www.opengroup.org/onlinep ... read_cond_wait.html

  1. (void) pthread_mutex_lock(&t.mn);
  2.         t.waiters++;
  3.     clock_gettime(CLOCK_REALTIME, &ts);
  4.     ts.tv_sec += 5;
  5.     rc = 0;
  6.     while (! mypredicate(&t) && rc == 0)
  7.         rc = pthread_cond_timedwait(&t.cond, &t.mn, &ts);
  8.     t.waiters--;
  9.     if (rc == 0) setmystate(&t);
  10. (void) pthread_mutex_unlock(&t.mn);
復(fù)制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2009-02-16 13:43 |只看該作者
再看ACE的,
WaitForSingleObject明明提供了延時時間,
ACE卻要改用絕對時間,再和 gettimeofday 的結(jié)果相減一下,
如果恰好減之前調(diào)整下時間,又完蛋了。
簡直自虐呀


  1. int
  2. ACE_OS::cond_timedwait (ACE_cond_t *cv,
  3.                         ACE_mutex_t *external_mutex,
  4.                         ACE_Time_Value *timeout)
  5. {
  6.   ACE_OS_TRACE ("ACE_OS::cond_timedwait");
  7. # if defined (ACE_HAS_THREADS)
  8.   // Handle the easy case first.
  9.   if (timeout == 0)
  10.     return ACE_OS::cond_wait (cv, external_mutex);
  11. #   if defined (ACE_HAS_WTHREADS) || defined (VXWORKS) || defined (ACE_PSOS)

  12.   // Prevent race conditions on the <waiters_> count.
  13.   ACE_OS::thread_mutex_lock (&cv->waiters_lock_);
  14.   cv->waiters_++;
  15.   ACE_OS::thread_mutex_unlock (&cv->waiters_lock_);

  16.   int result = 0;
  17.   ACE_Errno_Guard error (errno, 0);
  18.   int msec_timeout;

  19.   if (timeout->sec () == 0 && timeout->usec () == 0)
  20.     msec_timeout = 0; // Do a "poll."
  21.   else
  22.     {
  23.       // Note that we must convert between absolute time (which is
  24.       // passed as a parameter) and relative time (which is what
  25.       // WaitForSingleObjects() expects).
  26.       ACE_Time_Value relative_time (*timeout - ACE_OS::gettimeofday ());

  27.       // Watchout for situations where a context switch has caused the
  28.       // current time to be > the timeout.
  29.       if (relative_time < ACE_Time_Value::zero)
  30.         msec_timeout = 0;
  31.       else
  32.         msec_timeout = relative_time.msec ();
  33.     }

  34. #     if defined (ACE_HAS_SIGNAL_OBJECT_AND_WAIT)
  35.   if (external_mutex->type_ == USYNC_PROCESS)
  36.     // This call will automatically release the mutex and wait on the
  37.     // semaphore.
  38.     result = ::SignalObjectAndWait (external_mutex->proc_mutex_,
  39.                                     cv->sema_,
  40.                                     msec_timeout,
  41.                                     FALSE);

復(fù)制代碼

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
3 [報告]
發(fā)表于 2009-02-16 13:50 |只看該作者
這個錯誤我也犯過,
導(dǎo)致計算出來的帶寬有節(jié)律性的異常數(shù)據(jù)(毛刺)

論壇徽章:
0
4 [報告]
發(fā)表于 2009-02-16 13:58 |只看該作者

回復(fù) #3 flw 的帖子

可能用 times() 或 GetTickCount() 的返回值比較好。
后來怎么解決的?

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
5 [報告]
發(fā)表于 2009-02-16 14:04 |只看該作者
原帖由 太平紳士 于 2009-2-16 13:58 發(fā)表
可能用 times() 或 GetTickCount() 的返回值比較好。
后來怎么解決的?

后來用的 /proc/uptime,精度比較低,僅到了 10ms 級,但是經(jīng)過計算,認為誤差不影響業(yè)務(wù),所以就暫時這樣了。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP