zoukankan      html  css  js  c++  java
  • samephore()信号量跨线程通信

    samephore1:

    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    
    char name[100] = "haihualovefang";
    
    void main()
    {
        HANDLE hsem = CreateSemaphoreA(NULL, 0, 1, name);
        printf("创建成功");
        char ch = getch();
    
        //ReleaseMutex(mutex);//
    
        ReleaseSemaphore(hsem, 1, NULL);
        printf("触发信号量");
        CloseHandle(hsem);
    
    
    }

    samephore2:

    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    
    char name[100] = "haihualovefang";
    
    void main()
    {
    
        HANDLE hsem = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, TRUE, name);;
        if (hsem == NULL)
        {
            printf("打开失败");
            system("pause");
            return;
        }
        printf("等待-------");
        DWORD res = WaitForSingleObject(hsem, 20000);
        switch (res)
        {
        case WAIT_OBJECT_0:
            printf("收到信号-------");
            break;
        case WAIT_TIMEOUT:
            printf("超时没有收到-------");
            break;
        case WAIT_ABANDONED:
            printf("另外一个进程意外终止-------");
            break;
        default:
            break;
    
        }
        CloseHandle(hsem);
    
    
    
        system("pause");
    }
  • 相关阅读:
    oracle数据库闪回执行步骤——oracle数据库回退
    10.20总结
    10.11总结
    10.10总结
    10.9总结
    10.8总结
    10.7总结
    10.6总结
    10.5总结
    10.4总结
  • 原文地址:https://www.cnblogs.com/sjxbg/p/5792175.html
Copyright © 2011-2022 走看看