| |||||
Technical Support Support Resources
Product Information | C166: USING THE _ATOMIC_ FUNCTIONInformation in this article applies to:
QUESTIONHow can I use the _atomic_ function in my programs to create atomic sections? ANSWERThe _atomic_ and _endatomic_ library routines specify the start and end of an atomic code section. This section of code must be 4 instructions or less. Use atomic sections to protect program code from hardware interrupts. Instructions in an atomic section are executed as an atom and cannot be interrupted. For example:
#include <intrins.h>
bit testbit;
void function (int flag)
{
_atomic_ (0);
if (flag == 1)
testbit = 1;
_endatomic_ ();
}
Generates the following code: 0000 D120 ATOMIC #03H 0002 4881 CMP R8,#01H 0004 3D01 JMPR cc_NZ,?C0001 0006 0F00 R BSET testbit 0008 ?C0001: 0008 CB00 RET which uses the ATOMIC instruction to protect the specified code. MORE INFORMATION
SEE ALSOLast Reviewed: Friday, July 15, 2005 | ||||
| |||||