Atomic Operations

Does anyone know if there is possibility of doing Atomic Operations in
C++?
****** NEW Lines:
Particularly I am interested to have the solution on Windows NT Platform.
Example:
I want to COMMIT to a database (operation 1) and rename a file (operation 2) in one operation. Operation 2 is to be done after Operation 1 but I don't want to do Operation 1 without making sure that Operation 2 is also done!!

By Atomic I mean a block of code that either gets executed entirely
without interruption by the CPU or it does not get executed at all.

In MS Visual C++ (4.2CAB) use help/query type in the keyword
"synchronization" then read all the text up on "Application and Thread Support Classes" and "MultiThreading: How to Use Synchronization Classes".

At the kernel is Mutex, which you'll have to create, manage and observe to give your go / no go functionality.

There are two ways to handle pieces of code that need to be protected through mutual exclusion from other pieces of code.
1. Mutex Semaphores
2. Using "Critical Sections"

From your question I think the latter is more suitable for you. And there are two ways to use critical sections in windows NT.
1. By using the functions InitializeCriticalSection(), EnterCriticalSection(), LeaveCriticalSection()
2. By using the CCriticalSection and the CSingleLock or CMultiLock classes.

The first method is simple and straightforward, you initialize a so-called "critical-section" object somewhere in the initialization of your program, this object has no meaning in itself, but will be used in subsequent calls to EnterCriticalSection() and LeaveCriticalSection().

The second method is a bit more complicated but is more object-oriented. Using the second method, the class containing the critical section should include a data member of type CCriticalSection. Then in order to handle the controlled section, you should define a local variable of type CSingleLock (or CMultiLock if you want to wait on more than one CCriticalSection object). An example will show it best:

Assume class "List" has critical sections of code dealing with insertions and removals of items:

Featured Post

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects.
A brief on problem:
Lets take example problem for simplicity:
- I have a G…

The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.