Answer the question
In order to leave comments, you need to log in
atomicity in C++
Good day!
There was a problem: it is necessary to synchronize flows through testAndSet:
But here with atomic a problem, and without it in any way.
Can you tell me a library for atomically changing a variable in C++?
int atomic testAndSet ( char *lock ) {
char var;
var = *lock;
*lock = 1;
return var;
}
Answer the question
In order to leave comments, you need to log in
Without cross-platform requirements, you can use WInAPI and its Interlocked* functions.
I won't answer your specific question. But I myself write in the U ++ framework, where all these things are present in a cross-platform form:
Atomic t;
AtomicWrite(t, 1);
GCC has built-in functions like _sync_val_compare_and_swap().
Under Solaris, you can #include <atomic.h> where there are functions like atomic_cas().
Under Windows - API from the InterlockedCompareExchange () category.
I don't know of a universal solution. Several times I met inline assembler for this case under #ifdefs for different platforms.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question