If the register is yours, one of the “InterlockedBlahBlah” macros may be enough - AFAIK they generate a “lock” prefix to a machine instruction, which gets negotiated at compile time, doesn’t involve the OS, and makes the operation indivisible at front-side bus level. You can use these macros even inside critical sections without a problem. If however you’re accessing a PCI Configuration Register, the only legit way I know is to call the Microsoft PCI Bus Driver.
Yet your concept of “atomic” doesn’t jive. The only way you can have only one processor executing code is to halt the other processors. What you can achieve is mutual exclusion - that is, you can impose atomicity on an operation or on a sequence of operations that do something on a piece of data, meaning, that sequence executes as if it was the only instruction stream operating on the target piece of data.
You must be very aware that atomicity protects data, not code. You can protect a stretch of code with an Interlock, Spinlock or some other synchronization construct, yet that will achieve nothing if some other piece of code somewhere else acts on the same piece of data and doesn’t use the same lock. That’s why PCI configuration accesses in Windows are exposed to race conditions: the OS doesn’t supply a synchronization construct that “atomicizes” third party accesses to PCI registers, hence even though you set up a lock or a semaphore to protect your accesses to them, neither the OS nor some other program will go through that semaphore.
Try reading Gregory Andrews’s excellent “Foundations of Multithreaded, Parallel and Distributed Programs”. It’s all there, and much more!
Alberto.
----- Original Message -----
From: Darmawan Salihun
To: Windows System Software Devs Interest List
Sent: Tuesday, August 21, 2007 5:58 AM
Subject: Re: [ntdev] How to ensure atomic execution of driver code in Multiprocessor environment?
On 8/21/07, xxxxx@osr.com wrote:
Hmmmm… Maybe the OP can define for us what he, specifically, means by “atomic”. Atomic with regards to what?
This is the question Mr. Basov and Mr. Roddy are trying to get at with their replies.
Atomic in this context is “the only one executing without being interrupted”, including “assuring that other processor in the multiprocessor system” does not interfere with the execution of the code. Much like what Anton has described.
Regards,
Darmawan Salihun
--------------------------------------------------------------------
-= Human knowledge belongs to the world =- — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer