I have four threads, and i need to translate the data among these threads, the function like follow:
theadFunc(){
processing;
__sync();
processing;
}
Is there any sync functions in linux that make sure the threads will arrive at the same point.
In windows , I use atomic add and atomic compare to implement the __sync(), and i didn’t find the atomic compare function in Linux.
You can use GCC’s Atomic builtins to do a compare and swap, but you may want to consider using a pthreads barrier instead. See the documentation for
pthread_barrier_initandpthread_barrier_waitfor more information. You can also read this pthreads primer for a working example of barrier usage.