zoukankan      html  css  js  c++  java
  • 23.线程间的等待

    • 创建定时器
      1 HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL);
    • 设置定时器时间
      1   //设置时间
      2         LARGE_INTEGER time;
      3         time.QuadPart = -20000000;//以微秒为单位
    • 等待
      1 if (WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0)
      2         {
      3             printf("等待成功");
      4         }
      5         else
      6         {
      7             printf("等待失败");
      8         }

    完整代码

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <Windows.h>
     4 
     5 
     6 void main()
     7 {
     8     //创建定时器
     9     HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL);
    10     if (timer == NULL)
    11     {
    12         return;
    13     }
    14     else
    15     {
    16         //设置时间
    17         LARGE_INTEGER time;
    18         time.QuadPart = -20000000;//以微秒为单位
    19         //设置定时器等待2
    20         SetWaitableTimer(timer, &time, 0, NULL, 0, NULL);//设置定时器等待2两秒
    21 
    22         if (WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0)
    23         {
    24             printf("等待成功");
    25         }
    26         else
    27         {
    28             printf("等待失败");
    29         }
    30     }
    31 
    32     system("pause");
    33 }
  • 相关阅读:
    cs224n word2vec
    背包问题
    动态规划二
    动态规划
    递推求解
    Tmux 使用技巧
    LeetCode 75. Sort Colors
    LeetCode 18. 4Sum new
    LeetCode 148. Sort List
    LeetCode 147. Insertion Sort List
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8408760.html
Copyright © 2011-2022 走看看