Showing posts with label Visual Cpp Qs. Show all posts
Showing posts with label Visual Cpp Qs. Show all posts

Wednesday, October 12, 2016

Synchronization Primitives

Critical section, Mutex, Event, Semaphore and Waitable timers are the different available synchronization objects on windows.

Critical Section

Synchronizes threads (/allows one at a time) to have an access to a shared resource with in a process that it is created in and hence cannot be accessed across processes - limited scope. The remaining primitives have got system wide scope and so can be accessed across processes too.

Mutex

As the name indicates, mutually exclusive, so if one thread gets an access, all others will be on wait (or restrained from accessing) until the first one relinquishes - allows one thread at a time as if the critical sections does but it can be accessed across processes or network boundaries.
e.g. Toll gate (one vehicle per ticket)

Event

Mutex, upon relinquishing, causes to release one thread from the wait to have its turn among all bunch of threads, whereas event releases all the waiting threads in one go. Event signals (/notifies) all the waiting threads when a current thread is done its job.
e.g. Traffic Signals.

Semaphore

It maintains a count between zero and some maximum number, which indicates how many threads can access the shared resource simultaneously. It means one can restrict the no. of accesses to a resource. The count is reduced every time a thread gets an access to semaphore and is incremented every time a thread releases the semaphore. When the count reaches ZERO, no more threads can access the resource. The semaphore state is set to signaled when the count is greater than ZERO and non signaled when it is ZERO.
e.g. Movie tickets

Waitable Timers

Notifies one or more waiting threads that a specified time has arrived. A waitable timer object is a synchronization object whose state is set to signaled when the specified due time arrives. There are two types of waitable timers that can be created: manual-reset and synchronization. A timer of either type can also be a periodic timer.

Saturday, July 9, 2016

Windows Programming

Windows NT began supporting multi-threaded applications as so it was fully re-entrant and makes applications to run on it based on the preemptive approach.

What is a difference between an interrupt and an exception?

Interrupt is an asynchronous event, which does happen out of the context ( Means not related to what the process is executing) and are majorly generated by I/O device, processor clocks or timers etc. Whereas an exception is a synchronous condition happens due to the execution of a particular instruction. And one can reproduce this by running the program second time with the same setup and environment used.

How is 'trap' different from 'interrupt' and 'exception'?

Trap is a processor's mechanism to capture an execution thread when an interrupt or an exception occurs and transferring control to a trap handler, which is a function specific to a particular interrupt or exception.

What are the advantages of using DLL’s?

DLLs can be loaded during run-time (or program execution) when it is needed and hence it will not be part of the executable binary image. So EXE and DLL can vary independently and NO need to recompile the EXE when DLL is changed. And can be reused in other Applications too.

What are the different types of DLL’s?

SDK DLL (without MFC): Is a old style of creating DLL with pure Win32 calls.
Regular: Is an MFC DLL and can be used by both MFC and Non MFC Applications like VB and other languages, which supports DLL access. 
Extension: Is also an MFC DLL and can be used by MFC Applications only.

Friday, January 1, 2016

Basics

Books for Visual C++

Programming Visual C++ by David J. Kruglinski is the most popular one and Ivor Horton's Beginning Visual C++ but Kanithkar's Visual C++ Programming was the one that I began with.

Files and Purposes

  • .sln file records information about the projects in the solution - names, relative paths, VS version used and configuration platforms such as debug/release defined for both solution and projects etc..
  • .suo file, in which user options that apply to the solution will be recorded.
  • .sdf contains data about IntelliSense for the solution. 
  • .opensdf captures information about the state of the project. One would happen to see this file only while the project is open and disappears soon the solution is closed.


Reference(s)
MSDN
Ivor Horton's Beginning Visual C++ 2013