A
A
antonyter2012-11-15 18:48:43
linux
antonyter, 2012-11-15 18:48:43

Question about synchronization?

I'm using pthread to create a thread in a wrapper class with a bool mAnyField field. In the main function of thread “A”, I check the state of this field a very large number of times and if the field is false, I complete the execution. Actually the question is whether it is possible to change this field from another stream "B" without synchronization and, accordingly, read the field (in stream "A") also without synchronization? What is it for? I don't want to use synchronization just for performance reasons.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lesha_penguin, 2012-11-15
@antonyter

If only one thread changes the field, and all the others only read, then yes (only do not forget volatile for the field).

G
Gribozavr, 2012-11-15
@gribozavr

No. You need at least memory barriers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question