#Atomic operations on none atomic types.
35 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
okay but why dont you make the int atomic?
std::atomic<int>
doesnt need c++20
otherwise maybe you could have an atomic bool and only modify the ints value if that atomic bool is true? but then why not use std::atomic<int>
you can also use intrinsics and assume that pure write or read are atomic on most platforms (the later is risky ofc)
Are you stupid or something
Mutexes are slow
Are you stupid or something
quit with the aggression
I'm just curious why OP says cannot use atomic int and in the same time says that the reason he/she won't use mutex is that it is slow
so...
no atomic int, no mutex?
buy a faster computer xD
When you don't want to have the overhead of context switching you typically use atomic variables
whats the problem with atomic int
Use a custom binary semaphore with spinlock
The issue is is that there are two contending treads, a slow task and a fast task, the fast take does 1 "iteration" in 200us and MUST not go over, so is fairly speedy, Unfortunately i don't have control of the hardware or of the types used,
The function currently doing the job is a built-in OS function but i'm looking to make an abstraction layer for it.
I could look at changing them all to be atomic<int> but i would have to change a fair few files and theres all the validation that goes with that
using a spinlock is not really usable either as it is real time
If this is for work I'd recommend the team to invest in a spike/investigation/experiment before committing to any particular approach.
And I'd personally go for this option first.
Have the rubric for comparisons and metrics prepared before starting the experiment.
I'll have a look at the atomics and maybe a mutex approach too, i need to benchmark the times really.
We're doing a simulation build and a "normal" build, for the sim build timing requirements we don't have to care about, in the "normal" build we do, but the RTOS's mutex might be faster than the windows version.
other question is an atomic really required ? for what do you need it ? maybe the simplest solution is to decide afterwards what values too take
or let one thread wait till the other one is finished
That's a mutex 
i meant with .join()
yes thats mutex based
ah didnt know, learned something new thanks
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.