illustrating volatile : is this code thread-safe?

前端 未结 6 945
感动是毒
感动是毒 2020-12-17 05:49

I\'m trying to illustrate the use and importance of volatile with an example that would really not give a good result if volatile was omitted.

6条回答
  •  别那么骄傲
    2020-12-17 06:55

    To illustrate the importance of the volatile keyword when it comes to concurrency, all you need to do is make sure that the volatile field is modified and read in a separate threads.

提交回复
热议问题