mySemaphore copy 2 - #include "mySemaphore.h" # #include

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "mySemaphore.h" #include ". .\myException\myException.h" # mySemaphore::mySemaphore(string& sName,long initialCount,long maximumCount,int accessMode,BOOL canInherit) { // initialization sa = NULL; semaphore = NULL; semaphoreName = ""; initCount = 0; maxCount = 0; inherit = TRUE; i // create it if ( accessMode == CREATE ) { // security handling sa = (LPSECURITY_ATTRIBUTES)HeapAlloc(GetProcessHeap(),0,sizeof(SECURITY_ATTRIBUTES)); sa->nLength = sizeof(SECURITY_ATTRIBUTES); sa->lpSecurityDescriptor = NULL; //no restrictions sa->bInheritHandle = canInherit; // make sure the count is legal // normally, you want to create the semaphore will an initialcount = 0; // therefore, the original state of the semaphore is locked. // once the system finishes all the initialization work, it can // call unlock() to increase it to be 1, so other threads can // start to use it if ( maximumCount < initialCount ) { maximumCount = 1; initialCount = 0; } // create the semaphore if ( (semaphore = CreateSemaphore(sa,initialCount,maximumCount,sName.c_str())) == NULL)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2011 for the course COMPUTER 101 taught by Professor Bobthebuilder during the Spring '11 term at Columbia College.

Page1 / 3

mySemaphore copy 2 - #include "mySemaphore.h" # #include

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online