CreateSemaphore

Prototypes

HANDLE CreateSemaphore(SECURITY_ATTRIBUTES *AttributDeSecurites, LONG CompteurInitial, LONG CompteurMax, LPCSTR NomSemaphore);

Description

Crée le sémaphore NomSemaphore en l'initialisant avec CompteurInitial jetons. Le nombre de jetons maximum est CompteurMax.

Un sémaphore sert à synchroniser plusieurs threads de plusieurs processus.

Le résultat est le handle sur le sémaphore.

Exemple

#include <windows.h>
#include <winbase.h>

SECURITY_ATTRIBUTES AttributDeSecurites;
HANDLE hSemaphore;

AttributDeSecurites.nLength=sizeof(SECURITY_ATTRIBUTES);
AttributDeSecurites.lpSecurityDescriptor=NULL;
AttributDeSecurites.bInheritHandle=TRUE;
hSemaphore=CreateSemaphore(&AttributDeSecurites, 0, 1000, (LPCSTR)"MonSemaphore"); if (!hSemaphore) ...
CloseHandle(hSemaphore);
...

Avertissement

Si le sémaphore ne peut être créé, le résultat est NULL.

Voir aussi

OpenSemaphore pour retrouver un sémaphore déjà existant.