次の方法で共有


CSingleLock::Unlock

更新 : 2007 年 11 月

CSingleLock が所有する同期オブジェクトを解放します。

BOOL Unlock( ); 
BOOL Unlock(
   LONG lCount,
   LPLONG lPrevCount = NULL 
);

パラメータ

  • lCount
    解放するアクセスの数。1 以上であることが必要です。指定された数がオブジェクトの最大値を超えると、カウントは変更されず、FALSE を返します。

  • lPrevCount
    同期オブジェクトの直前のカウントを受け取る変数へのポインタ。NULL の場合、前回のカウントは返されません。

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。

解説

この関数は、CSingleLock のデストラクタから呼び出されます。

セマフォの 1 以上のアクセス カウントを解放するには、Unlock の 2 番目の形式を使用し、解放するアクセス数を指定します。

使用例

// m_Mutex is a data member (of type CMutex)
// of an existing class that implements the resource being shared.

// Relate the synchronization object (m_Mutex) with
// our CSingleLock object. 
CSingleLock singleLock(&m_Mutex);

// Attempt to lock the shared resource
if (singleLock.Lock(100))    // Wait 100 ms...
{
    // We were able to lock the resource;
    // we may now work with the data associated with the mutex...

    // Now that we are finished, unlock the resource for others.
    singleLock.Unlock();
}

必要条件

ヘッダー : afxmt.h

参照

参照

CSingleLock クラス

階層図

その他の技術情報

CSingleLock のメンバ