Skip to main content

Thread synchronization part 2 (CEVent)

CEvent:-
When a synchronization object that allow one thread to notify another that event has occurred now another thread can perform task.one thread is reading a doc and another is writing the thread .that time first writing thread write the file and when its task has done then its single to other thread now reading thread can read the thread.
CEvent object is two types :-
1. Manul :-Manual CEvent object stays in the state set by SetEvent or ResetEvent untill the other function is called
2. Automatic:- in an automatic CEvent object automatically returns to a nonsignaled state after at least one thread is released.

CreateEvent function's argument decide it  is a maual or auto event and it declare the event a name or unnamed event object,SetEvent function is used to put thread in signal state and ResetEvent function is used to put thread in non signal state.OpenEvent function is used to open a already created event by createEvent () function.


HANDLE WINAPI CreateEvent(
  __in_opt  LPSECURITY_ATTRIBUTES lpEventAttributes,//default is NULL
  __in      BOOL bManualReset,//TRUE for Manual reset and FALSE parameter for AUTO
  __in      BOOL bInitialState,//FALSE for nonsignal state and TRUE for Nonsignal State
  __in_opt  LPCTSTR lpName// assign a event name default is NULL for unnamed event
);
it return a HANDLE which we pass in setEvent and ResetEvent method as a argument.

Semaphore Synchronization Object:-

this is Synchronize object that allows the resource for count zero and a maximum number of threads.if threads enter in semaphore its increament and when if thread completed his task it 
decrement with one.and when count reach at zero semaphore in non signal state and otherwise 
its in signal state.
HANDLE WINAPI CreateSemaphore(
  __in_opt  LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
  __in      LONG lInitialCount,
  __in      LONG lMaximumCount,
  __in_opt  LPCTSTR lpName
);

Comments

Popular posts from this blog

Microservice Architecture

Agile development & Deployment is difficult in case of ____ Monolithic Software built as microservices can, by definition, be broken down into multiple component services ? True Separating components with conflicting resource requirements falls under the bucket of _ Microservices Complexity of developing, testing & deploying distributed system, Handling partial failures account to disadvantages of Microservices Benefits of Microservices include - All the options Decomposition of Microservices based on 2 categories namely Business capability , Subdomain Simple to Develop, Test, Deploy, Scale represents ____ Monolithic Is Microservice is considered as subset of SOA ? True The 3Cs of Microservices includes all these except Control Microservice Architecture adapts following concepts All the options The client expects a timely response from the service and might even block while it waits represents__client service interaction styles Synch...

What is Document/View Architecture in MFC?

By default MFC application wizard creats with an skeleton with a document class and another is view class.MFC seperates data management into these two class.The document class store the data and print the data and view display the data and manages the user interaction with it. Notepad is simple example for SDI application. or ALL MFC application which have user interface follow this architecture. Any MFC application creates with two basic skeleton one is document class and another is view class.document manages the data for multiple view,and view class displays the data. MFC document/view architecture makes it easy to support multiple view,multiple document types, splitter windows and other valuable user interface features. . For exm:- in SDI application we have following major class:- 1. CMainFrameApp:- Frame class derived  from the CFrameWnd 2. CMySDIView :- View class derived  from the CView class 3. CMainDoc :- Document class derived  from the CDoc...