Stale value of Shared variable

后端 未结 4 432
青春惊慌失措
青春惊慌失措 2021-01-06 08:38

While reading Concurrency in practice I read that:

NoVisibility demonstrated one of the ways that insufficiently synchronized programs can c

4条回答
  •  难免孤独
    2021-01-06 09:02

    It's saying that in main the intention is to set number=42 and ready=true at the same time, but since they were called in this particular order there is a race condition with your ReaderThread where it could (probably will) print out the number even though we really don't want it to.

    They would like you to synchronize those 2 variables to be set together.

提交回复
热议问题