建立互斥量的时候使用的参数是nil,false,nil然后在主线程使用WaitForSingleObject (hMutex, INFINITE),并在一个线程使用WaitForSingleObject (hMutex, INFINITE),但发现,无论是否主线程是否已经ReleaseMutex (hMutex),线程都不会停在WaitForSingleObject那里,请问这个互斥量怎么使用才能达到效果?

解决方案 »

  1.   

    建立互斥量的时候使用的参数是nil,false,nil 参数错误
    lpName 
    Pointer to a null-terminated string specifying the name of the mutex object. The name is limited to MAX_PATH characters and can contain any character except the backslash path-separator character (\). Name comparison is case sensitive. 
    If lpName matches the name of an existing named mutex object, this function requests MUTEX_ALL_ACCESS access to the existing object. In this case, the bInitialOwner parameter is ignored because it has already been set by the creating process. If the lpMutexAttributes parameter is not NULL, it determines whether the handle can be inherited, but its security-descriptor member is ignored. If lpName is NULL, the mutex object is created without a name. If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same name space. 你随便取个名字试试 传入 PChar('aaa')
      

  2.   

    可是这些参数是Delphi5开发人员指南上的代码啊?