int main() { /*int lockId = 1;*/ /* Halt(); */ /*void (*ptrfunc)();*/ /*ptrfunc = &calc;*/ int i; lockid = CreateLock("userProg1Lock",13); Acquire(lockid); WriteToConsole("\nAfter Exec - userprog 1\n\0", 26, -1, -1); Fork(fun1); /*WriteToConsole("After Fork To Multi\n\0", 21, -1, -1);*/ i=0; while(i<10){ WriteToConsole("\nIn user prog1 loop %d - x: %d\n\0", i, x, -1); i++;x++; } Release(lockid); Exit(0); }
int main() { WriteToConsole("\nExec matmult\n\0",-1,-1,-1); Exec("../test/matmult"); WriteToConsole("\nExec sort\n\0",-1,-1,-1); Exec("../test/sort"); Exit(0); }
void fun1() { WriteToConsole("In Function 1 - user prog 1\n\0",-1,-1,-1); Acquire(lockid); WriteToConsole("\nIn user prog1 fun1 - x: %d\n\0", x, -1, -1); Release(lockid); DeleteLock(lockid); WriteToConsole("\nDeleted Lock Id: %d\n\0", lockid, -1, -1); Exit(0); }
int main() { int lock3,mv3,cv3; lock3 = CreateLock("lock3",5); cv3 = CreateCV("cv3",3); mv3 = CreateMV("mv3",3,5); WriteToConsole("\nAcquiring lock3 in rpcclient5\n\0", -1, -1, -1); if((Acquire("lock3",5)) == -1){ WriteToConsole("Error acquiring lock3 in rpcclient5\n\0",-1,-1,-1); Exit(0); } if((Wait("cv3",3, "lock3",5)) == -1){ WriteToConsole("Error waiting on cv3 and lock3 in rpcClient1\n\0",-1,-1,-1); Exit(0); } WriteToConsole("\nGot Signal on cv3 lock3 from rpcClient1\n\0", -1, -1, -1); WriteToConsole("\nValue of mv3 index 3 set by rpcClient1 is %d\n\0", GetMV("mv3",3,3), -1, -1); Release("lock3",5); DeleteLock("lock3",5); WriteToConsole(" Deleted Lock3\n\0",-1,-1,-1); DeleteMV("mv3",3); WriteToConsole(" Deleted MV3\n\0",-1,-1,-1); DeleteCV("cv3",3); WriteToConsole(" Deleted CV3\n\0",-1,-1,-1); Exit(0); }
int main() { int lockId, lockStatus,locktemp,mv; WriteToConsole("\nUser Program 4\n",-1,-1,-1); WriteToConsole("\nCreating Monitor Variable - mv1\n",-1,-1,-1); mv = CreateMV("mv1",3,0); WriteToConsole("\nCreating Lock - lock2\n",-1,-1,-1); if((locktemp = CreateLock("lock2",5)) == -1){ WriteToConsole("Error Creating lock2 in User Program 4\n\0",-1,-1,-1); Exit(0); } WriteToConsole("\nAcquiring lock2\n", -1, -1, -1); if((Acquire("lock2",5)) == -1){ WriteToConsole("Error acquiring lock2 in User Program 4\n\0",-1,-1,-1); Exit(0); } WriteToConsole("\nReleasing Lock lock2\n",-1,-1,-1); Release("lock2",5); WriteToConsole("\nUser Program 4 Exiting\n",-1,-1,-1); Exit(0); }
bool CreateConnectedSocket(SOCKET *pSocket, char *szHost, int nPortNo) { struct sockaddr_in ServerAddress; struct hostent *Server; //Create a socket *pSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (INVALID_SOCKET == *pSocket) { WriteToConsole("\nError occurred while opening socket: %d.", WSAGetLastError()); return false; //error } //Server name will be supplied as a commandline argument //Get the server details Server = gethostbyname(szHost); if (Server == NULL) { closesocket(*pSocket); WriteToConsole("\nError occurred no such host."); return false; //error } //Cleanup and Init with 0 the ServerAddress ZeroMemory((char *) &ServerAddress, sizeof(ServerAddress)); ServerAddress.sin_family = AF_INET; //Assign the information received from gethostbyname() CopyMemory((char *)&ServerAddress.sin_addr.s_addr, (char *)Server->h_addr, Server->h_length); ServerAddress.sin_port = htons(nPortNo); //Establish connection with the server if (SOCKET_ERROR == connect(*pSocket, reinterpret_cast<const struct sockaddr *>(&ServerAddress),sizeof(ServerAddress))) { closesocket(*pSocket); WriteToConsole("\nError occurred while connecting."); return false; //error } printf("DEBUG at %d: server address %s\n", __LINE__, inet_ntoa(ServerAddress.sin_addr)); return true; }
void Log::Write() { std::string logMessage = logMessageStream->str(); logMessageStream->str(std::string()); WriteToConsole(logLevel, logMessage); WriteToFile(logLevel, logMessage); }
Log::~Log() { logMessageStream << std::endl; std::string logMessage = logMessageStream.str(); WriteToConsole(logLevel, logMessage); WriteToFile(logLevel, logMessage); }
void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text) { #if defined(_WIN32) if (hThread == NULL) WriteToConsole(Level, Text, strlen(Text)); else SendToThread(Level, Text); #else char ColorAttr[16] = ""; char ResetAttr[16] = ""; if (bUseColor) { strcpy(ResetAttr, "\033[0m"); switch (Level) { case NOTICE_LEVEL: // light green strcpy(ColorAttr, "\033[92m"); break; case ERROR_LEVEL: // light red strcpy(ColorAttr, "\033[91m"); break; case WARNING_LEVEL: // light yellow strcpy(ColorAttr, "\033[93m"); break; default: break; } } fprintf(stderr, "%s%s%s", ColorAttr, Text, ResetAttr); #endif }
DWORD WINAPI WorkerThread(LPVOID lpParam) { ThreadInfo *pThreadInfo = (ThreadInfo*)lpParam; char szTemp[MAX_BUFFER_LEN]; int nBytesSent = 0; int nBytesRecv = 0; for (int ii = 0; ii < pThreadInfo->m_nNoOfSends; ii++) { sprintf(szTemp, "%d. %s", ii+1, pThreadInfo->m_szBuffer); RE_SEND: //Send the message to the server, include the NULL as well nBytesSent = send(pThreadInfo->m_Socket, szTemp, strlen(szTemp), 0); if (SOCKET_ERROR == nBytesSent) { WriteToConsole("\nError occurred while writing to socket %ld.", WSAGetLastError()); //return 1; //error Sleep(3000); CreateConnectedSocket(&(pThreadInfo->m_Socket), m_Host, m_Port); memset(szTemp, 0, MAX_BUFFER_LEN); sprintf(szTemp, "DEBUG at %d: Re-sending ...", __LINE__); goto RE_SEND; } //Get the message from the server nBytesRecv = recv(pThreadInfo->m_Socket, szTemp, 255, 0); if (SOCKET_ERROR == nBytesRecv) { WriteToConsole("\nError occurred while reading from socket %ld.", WSAGetLastError()); //return 1; //error Sleep(3000); CreateConnectedSocket(&(pThreadInfo->m_Socket), m_Host, m_Port); memset(szTemp, 0, MAX_BUFFER_LEN); sprintf(szTemp, "DEBUG at %d: Re-recving ...", __LINE__); goto RE_SEND; } //Display the server message WriteToConsole("\nServer sent the following message: %s", szTemp); } return 0; //success }
void cLogMgr::Write(eLogLevel verbosity, std::string entry) { if (ENABLE_LOGGING) { WriteToConsole(verbosity, GetTimeStamp() + GetVerbosityToken(verbosity) + entry); WriteToFile(verbosity, GetTimeStamp() + GetVerbosityToken(verbosity) + entry); } }
void cLogMgr::WriteToFile(eLogLevel verbosity, std::string entry) { if (IsInVerbosityRange (verbosity)) { (mOutfile != "") ? *mWriter << entry << std::endl : WriteToConsole(FATAL, "cLogMgr::WriteToFile >>>> Could not print to file. No path specified"); } }
bool CSystem::Init() { HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); AllocConsole(); consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); FILE* file = NULL; freopen_s(&file, "CONOUT$", "w", stdout); // Initialize the width and height of the screen to 0 before it is assigned int screenWidth = 0; int screenHeight = 0; bool result; // Init the windows api InitWindows(screenWidth, screenHeight); WriteToConsole("Initialized Window", INFO); // Create a new input object used to handle user input m_pInput = new CInputManager(); if(!m_pInput) { return false; } // Initialize the input object m_pInput->Init(); WriteToConsole("Initialized Input", INFO); m_pRenderer = new CRenderer(); if(!m_pRenderer) { return false; } // Initialize the renderer result = m_pRenderer->Init(screenWidth, screenHeight, m_hwnd); if(!result) { WriteToConsole("Renderer initialized with errors.", ERRORS); return false; } WriteToConsole("Renderer initialized successfully!", INFO); return true; }
int main() { int lockId, lockStatus; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockId = CreateLock("lock1",5); if(lockId == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created, Lock Id returned by the server is : %d\n\0", lockId, -1, -1); } WriteToConsole("\nTrying to acquire lock with id: %d different than what was returned by server\n\0",lockId+10,-1,-1); lockStatus = Acquire(lockId + 10); if(lockStatus == -1) { WriteToConsole("\nInvalid Lock Id. Failed to Acquire Lock. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nAcquired Lock\n\0", -1, -1, -1); } Exit(0); }
cLogMgr::cLogMgr() { // set inital logger settings mOutfile = LOG_PATH; mVerbosity = LOG_VERBOSITY; mActive = true; if (mOutfile != "") { mWriter = new std::ofstream(mOutfile); Write(INFO, "OVERSEER log manager initalized"); Write(INFO, "Set log verbosity: " + GetVerbosityName()); Write(INFO, ("Logging printed to " + toString(mOutfile))); } else { WriteToConsole(INFO, "OVERSEER log manager initalized"); WriteToConsole(INFO, "Set log verbosity: " + GetVerbosityName()); WriteToConsole(INFO, "No file will be written"); } }
VOID PrintToConsole( LPWSTR lpFormat, ...) { WCHAR szBuffer[MAX_BUFFER_SIZE]; va_list arg_ptr; va_start(arg_ptr, lpFormat); _vsnwprintf(szBuffer, MAX_BUFFER_SIZE, lpFormat, arg_ptr); va_end(arg_ptr); WriteToConsole(szBuffer); }
VOID PrintPadding( WCHAR chr, INT nPaddedLength) { WCHAR szMsgBuffer[MAX_BUFFER_SIZE]; INT i; for (i = 0; i < nPaddedLength; i++) szMsgBuffer[i] = chr; szMsgBuffer[nPaddedLength] = UNICODE_NULL; WriteToConsole(szMsgBuffer); }
VOID PrintResourceString( INT resID, ...) { WCHAR szMsgBuffer[MAX_BUFFER_SIZE]; WCHAR szOutBuffer[MAX_BUFFER_SIZE]; va_list arg_ptr; va_start(arg_ptr, resID); LoadStringW(GetModuleHandle(NULL), resID, szMsgBuffer, MAX_BUFFER_SIZE); _vsnwprintf(szOutBuffer, MAX_BUFFER_SIZE, szMsgBuffer, arg_ptr); va_end(arg_ptr); WriteToConsole(szOutBuffer); }
VOID PrintPaddedResourceString( INT resID, INT nPaddedLength) { WCHAR szMsgBuffer[MAX_BUFFER_SIZE]; INT nLength, i; nLength = LoadStringW(GetModuleHandle(NULL), resID, szMsgBuffer, MAX_BUFFER_SIZE); if (nLength < nPaddedLength) { for (i = nLength; i < nPaddedLength; i++) szMsgBuffer[i] = L' '; szMsgBuffer[nPaddedLength] = UNICODE_NULL; } WriteToConsole(szMsgBuffer); }
int main() { int i; delay(551); for(i = 0 ; i < MAX_TC ; i++) { WriteToConsole("\nExec Ticket Clerk : %d\n\0", i, -1, -1); Exec("../test/ticketClerk"); } for(i = 0 ; i < MAX_CC ; i++) { Exec("../test/concessionClerk"); } for(i = 0 ; i < MAX_TT ; i++) { Exec("../test/ticketTaker"); } Exit(0); }
void ConsoleListener::LogWriterThread() { char *logLocal = new char[LOG_PENDING_MAX]; int logLocalSize = 0; while (true) { WaitForSingleObject(hTriggerEvent, INFINITE); Sleep(LOG_LATENCY_DELAY_MS); u32 logRemotePos = Common::AtomicLoadAcquire(logPendingWritePos); if (logRemotePos == (u32) -1) break; else if (logRemotePos == logPendingReadPos) continue; else { EnterCriticalSection(&criticalSection); logRemotePos = Common::AtomicLoadAcquire(logPendingWritePos); int start = 0; if (logRemotePos < logPendingReadPos) { const int count = LOG_PENDING_MAX - logPendingReadPos; memcpy(logLocal + start, logPending + logPendingReadPos, count); start = count; logPendingReadPos = 0; } const int count = logRemotePos - logPendingReadPos; memcpy(logLocal + start, logPending + logPendingReadPos, count); logPendingReadPos += count; LeaveCriticalSection(&criticalSection); // Double check. if (logPendingWritePos == (u32) -1) break; logLocalSize = start + count; } for (char *Text = logLocal, *End = logLocal + logLocalSize; Text < End; ) { LogTypes::LOG_LEVELS Level = LogTypes::LINFO; char *next = (char *) memchr(Text + 1, '\033', End - Text); size_t Len = next - Text; if (next == NULL) Len = End - Text; if (Text[0] == '\033' && Text + 1 < End) { Level = (LogTypes::LOG_LEVELS) (Text[1] - '0'); Len -= 2; Text += 2; } // Make sure we didn't start quitting. This is kinda slow. if (logPendingWritePos == (u32) -1) break; WriteToConsole(Level, Text, Len); Text += Len; } } delete [] logLocal; }
int main() { int lockId, lockStatus, cvId, cvStatus, mvId, mvStatus, mvValue, signalStatus; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockId = CreateLock("lock1",5); if(lockId == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created, Lock Id returned by the server is : %d\n\0", lockId, -1, -1); } WriteToConsole("\nCreating a CV\n\0", -1, -1, -1); cvId = CreateCV("cv1",3); if(cvId == -1) { WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nCV Created, CV Id returned by the server is : %d\n\0", cvId, -1, -1); } WriteToConsole("\nCreating a MV\n\0", -1, -1, -1); mvId = CreateMV("mv1",3, 5); if(mvId == -1) { WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV Created, MV Id returned by the server is : %d\n\0", mvId, -1, -1); } WriteToConsole("\nAcquiring Lock\n",-1,-1,-1); lockStatus = Acquire(lockId); if(lockStatus == -1) { WriteToConsole("\nFailed to Acquire Lock. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nAcquired Lock\n\0", -1, -1, -1); } WriteToConsole("\nGetting MV value at index 1\n", -1, -1, -1); mvValue = GetMV(mvId, 1); if(mvValue == -1) { WriteToConsole("\nFailed to Get value from MV. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nGot value from MV at index 1: %d.\n\0", mvValue, -1, -1); } if(mvValue == 100) { signalStatus = Signal(cvId, lockId); if(signalStatus == -1) { WriteToConsole("\nFailed to Signal on the given Condition\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nSignalling on CV1 with Lock1\n\0", -1, -1, -1); } } WriteToConsole("\nSetting MV index 2 to 222\n", -1, -1, -1); mvStatus = SetMV(mvId, 2, 222); if(mvStatus == -1) { WriteToConsole("\nFailed to Set MV. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV set successfully.\n\0", -1, -1, -1); } WriteToConsole("\nReleasing Lock\n\0", -1, -1, -1); Release(lockId); if(lockStatus == -1) { WriteToConsole("\nFailed to Release Lock. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nReleased Lock\n\0", -1, -1, -1); } Exit(0); }
int main() { int lock2, cv2, mv2; if((lock2 = CreateLock("lock2",5)) == -1){ WriteToConsole("Error Creating lock2 in rpcClient4\n\0",-1,-1,-1); Exit(0); } WriteToConsole("lock2 created in rpcClient4 with lockid: %d\n\0",lock2,-1,-1); WriteToConsole("cv1 created in rpcClient4 with CVid: %d\n\0",cv2,-1,-1); if((cv2 = CreateCV("cv2", 3)) == -1){ WriteToConsole("Error Creating CV2 in rpcClient4\n\0",-1,-1,-1); Exit(0); } WriteToConsole("cv2 created in rpcClient4 with CVid: %d\n\0",cv2,-1,-1); if((mv2 = CreateMV("mv2", 3, 5)) == -1){ WriteToConsole("Error Creating MV2 in rpcClient2\n\0",-1,-1,-1); Exit(0); } WriteToConsole("mv2 created in rpcClient2 with MVid: %d\n\0",mv2,-1,-1); if((Acquire(lock2)) == -1){ WriteToConsole("Error acquiring lock2 with id:%d in rpcClient4\n\0",lock2,-1,-1); Exit(0); } WriteToConsole("\nAcquired lock2: %d\n\0", lock2, -1, -1); WriteToConsole("\nValue of MV2 index 0 set by rpcClient4 is %d\n\0", GetMV(mv2,0), -1, -1); if((SetMV(mv2, 1, 5)) == -1){ WriteToConsole("Error setting mv2 in rpcClient4\n\0",-1,-1,-1); Exit(0); } WriteToConsole("\nMV2 index: 1 set to 5 by rpcClient4\n\0", -1, -1, -1); WriteToConsole("\nSignalling on CV2 Lock2 to rpcClient1\n\0", -1, -1, -1); if((Signal(cv2, lock2)) == -1){ WriteToConsole("Error signalling on cv2 and lock2 in rpcClient4\n\0",-1,-1,-1); Exit(0); } if((Release(lock2)) == -1){ WriteToConsole("Error releasing lock2 with id:%d in rpcClient1\n\0",lock2,-1,-1); Exit(0); } WriteToConsole("\nReleased lock2: %d\n\0", lock2, -1, -1); DeleteLock(lock2); WriteToConsole("Sent DeletLock Request id: %d\n\0",lock2,-1,-1); DeleteCV(cv2); WriteToConsole("Sent DeletCV Request id: %d\n\0",cv2,-1,-1); DeleteMV(mv2); WriteToConsole("Sent DeleteMV Request id: %d\n\0",mv2,-1,-1); Exit(0); }
int main() { int lockStatus, cvStatus, mvStatus, waitStatus; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockStatus = CreateLock("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created by the server\n\0", -1 , -1, -1); } cvStatus = CreateCV("cv1",3); if(cvStatus == -1) { WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nCV Created by the server\n\0", -1 , -1, -1); } mvStatus = CreateMV("mv1", 3, 1); if(mvStatus == -1) { WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV Created by the server\n\0", -1 , -1, -1); } WriteToConsole("\nAcquiring Lock\n",-1,-1,-1); lockStatus = Acquire("lock1",5); if(lockStatus == -1) { WriteToConsole("\nFailed to Acquire Lock. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nAcquired Lock\n\0", -1, -1, -1); } WriteToConsole("\nSetting MV1 to 100.\n",-1,-1,-1); SetMV("mv1", 3, 0, 100); WriteToConsole("\nWaiting on the condition cv1 with lock1.\n",-1,-1,-1); waitStatus = Wait("cv1",3,"lock1",5); if(lockStatus == -1) { WriteToConsole("\nServer failed to wait. Exiting program.\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nClient 1 is waiting. Start client 2 to signal.\0n", -1, -1, -1); } WriteToConsole("\nGot signal from client 2.\n\0", -1, -1, -1); WriteToConsole("\nReleasing Lock\n\0", -1, -1, -1); lockStatus = Release("lock1",5); if(lockStatus == -1) { WriteToConsole("\nFailed to Release Lock. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nReleased Lock\n\0", -1, -1, -1); } WriteToConsole("\nDeleting Lock\n\0", -1, -1, -1); lockStatus = DeleteLock("lock1",5); if(lockStatus == -1) { WriteToConsole("\nFailed to Delete Lock. Exiting Program\0n", -1, -1, -1); Exit(0); } else { WriteToConsole("\nDeleted Lock\n\0", -1, -1, -1); } Exit(0); }
int main() { int lockStatus, cvStatus, mvStatus, mvId, mvValue; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockStatus = CreateLock("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created by the server.\n\0", -1, -1, -1); } WriteToConsole("\nCreating a MV\n\0", -1, -1, -1); mvStatus = CreateMV("mv1",3, 5); if(mvStatus == -1) { WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV Created by the server.\n\0", -1, -1, -1); } WriteToConsole("\nAcquiring lock to access Monitor Variable\n\0", -1, -1, -1); lockStatus = Acquire("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while acquiring Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock acquired by the server.\n\0", -1, -1, -1); } WriteToConsole("\nSetting MV to 100\n", -1, -1, -1); mvStatus = SetMV("mv1",3, 1, 100); if(mvStatus == -1) { WriteToConsole("\nFailed to Set MV. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV set successfully.\n\0", -1, -1, -1); } WriteToConsole("\nTrying to fetch value at invalid mv Index : %d\n\0", 21, -1,-1); mvValue = GetMV("mv1",3, 20); if(mvValue == -1) { WriteToConsole("\nInvalid mvIndex, Failed to fetch value at given index. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nAbnormal Execution\n\0", -1, -1, -1); } Exit(0); }
int main() { int lockStatus, cvId, waitStatus; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockStatus = CreateLock("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created by the server.\n\0", -1, -1, -1); } WriteToConsole("\nCreating a CV\n\0", -1, -1, -1); cvId = CreateCV("cv1",3); if(cvId == -1) { WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nCV Created by the server.", -1, -1, -1); } WriteToConsole("\nAcquiring Lock.\n\0", -1, -1, -1); lockStatus = Acquire("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while Acquiring Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock acquired.\n\0", -1, -1, -1); } WriteToConsole("\nCalling Wait on lock1 and cv1.\n\0",-1, -1,-1); waitStatus = Wait("cv1",3, "lock1",5); if(waitStatus == -1) { WriteToConsole("\nError, Not the Lock owner. Exiting Program.\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nServer waiting on the given condition. Now start client 2\n\0", -1, -1, -1); } WriteToConsole("\nReleasing Lock.\n\0", -1, -1, -1); lockStatus = Release("lock1",5); if(lockStatus == -1) { WriteToConsole("\nError Occurred while Releasing Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock released.\n\0", -1, -1, -1); } Exit(0); }
int main() { int lockId, lockStatus, cvId, mvStatus, mvId, mvValue, lockId1, lockId2; WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1); lockId = CreateLock("lock1",5); if(lockId == -1) { WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nLock Created, Lock Id returned by the server is : %d\n\0", lockId, -1, -1); } WriteToConsole("\nCreating a CV\n\0", -1, -1, -1); cvId = CreateCV("cv1",3); if(cvId == -1) { WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nCV Created, CV Id returned by the server is : %d\n\0", cvId, -1, -1); } WriteToConsole("\nCreating a MV\n\0", -1, -1, -1); mvId = CreateMV("mv1",3, 5); if(mvId == -1) { WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV Created, MV Id returned by the server is : %d\n\0", mvId, -1, -1); } WriteToConsole("\nSetting MV to 100\n", -1, -1, -1); mvStatus = SetMV(mvId, 1, 100); if(mvStatus == -1) { WriteToConsole("\nFailed to Set MV. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV set successfully.\n\0", -1, -1, -1); } WriteToConsole("\nDeleting MV\n", -1, -1, -1); mvStatus = DeleteMV(mvId); if(mvStatus == -1) { WriteToConsole("\nFailed to Delete MV. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nMV deleted successfully.\n\0", -1, -1, -1); } WriteToConsole("\nTrying to fetch value from MV which is deleted : %d\n\0",mvId,-1,-1); mvValue = GetMV(mvId+25, 1); if(mvValue == -1) { WriteToConsole("\nInvalid mv Id. Exiting Program\n\0", -1, -1, -1); Exit(0); } else { WriteToConsole("\nAbnormal Execution\n\0", -1, -1, -1); } Exit(0); }