atomicity in C++

0 like 0 dislike
55 views
Good day!

Did the task: it is necessary to synchronize using testAndSet flows:
int atomic testAndSet ( char *lock ) {
char var;
var = *lock;
*lock = 1;
return var;
}

But with a atomic problem, but it does not.
Prompt library for atomic variable in C++?
by | 55 views

3 Answers

0 like 0 dislike
Without the requirements of crossplatforming you can use WInAPI and its Interlocked* functions.
by
0 like 0 dislike
Specifically to your question can not be answered. But the writing of the framework U++ where all these things are present in a cross-platform way:
Atomic t;
AtomicWrite(t, 1);
by
0 like 0 dislike
In GCC have built-in functions of the form _sync_val_compare_and_swap().
Under Solaris you can do #include where there is a sort function atomic_cas().
Windows — API from the category of InterlockedCompareExchange().
\r
Universal solutions are not know. I met several times for this case inline assembler #ifdef'AMI for different platforms.
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
7 answers
0 like 0 dislike
4 answers
asked Mar 24, 2019 by Hypuk
0 like 0 dislike
3 answers
0 like 0 dislike
7 answers
asked Mar 23, 2019 by kirsan_vlz
110,608 questions
257,186 answers
0 comments
28,804 users