• 资源同步


    curr_sequence = (UCHAR) InterlockedIncrement(&last_sequence);

    refcount = InterlockedDecrement(&This->RefCount);

    		InitializeCriticalSection(&g_cs);
    		MeasureConcurrentOperation(TEXT("Critical Section"), nThreads, CriticalSectionCallback);
    		// Don't forget to cleanup
    		DeleteCriticalSection(&g_cs);
    

      

    void WINAPI CriticalSectionCallback()
    {
    	EnterCriticalSection(&g_cs);
    	gv_value = 0;
    	LeaveCriticalSection(&g_cs);
    }
    

      Slim Reader/Writer lock

          // Prepare the Slim Reader/Writer lock
    		InitializeSRWLock(&g_srwLock);
    		MeasureConcurrentOperation(TEXT("SRWLock Read"), nThreads, SRWLockReadCallback);
    		MeasureConcurrentOperation(TEXT("SRWLock Write"), nThreads, SRWLockWriteCallback);
    		// NOTE: You can't cleanup a Slim Reader/Writer lock

      

    void WINAPI SRWLockReadCallback() {
    	AcquireSRWLockShared(&g_srwLock);
    	gv_value = 0;
    	ReleaseSRWLockShared(&g_srwLock);
    }
    

      

    the mutex

    		// Prepare the mutex
    		g_hMutex = CreateMutex(NULL, false, NULL);
    		MeasureConcurrentOperation(TEXT("Mutex"), nThreads, MutexCallback);
    		CloseHandle(g_hMutex);
    

      

    HANDLE g_hMutex;
    void WINAPI MutexCallback()
    {
    	WaitForSingleObject(g_hMutex, INFINITE);
    	gv_value = 0;
    	ReleaseMutex(g_hMutex);
    }
    

      

     有两种不同类型的事件对象。一种是人工重置的事件,另一种是自动重置的事件。当人工重置的事件得到通知时,等待该事件的所有线程均变为可调度线程。当一个自动重置的事件得到通知时,等待该事件的线程中只有一个线程变为可调度线程。

    If this parameter is TRUE, the function creates a manual-reset event object, which requires the use of the ResetEvent function to set the event state to nonsignaled. If this parameter is FALSE, the function creates an auto-reset event object, and system automatically resets the event state to nonsignaled after a single waiting thread has been released.

  • 相关阅读:
    ActionScript 条件编译
    FLASH通讯小结
    关于ob_start()
    剖析PHP中的输出缓冲
    Ext.app.controller的refs
    php多线程解决之stream_socket_client
    谷歌的JQuery库
    PHP计划任务之关闭浏览器后仍然继续执行的函数
    关于php调用可执行程序,在后台运行而不让页面等待
    把预定义的字符串转化为html标签
  • 原文地址:https://www.cnblogs.com/chunyou128/p/15993603.html
Copyright © 2020-2023  润新知