what's problem will you face in the multiple threading tasks

Posted apanda009

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了what's problem will you face in the multiple threading tasks相关的知识,希望对你有一定的参考价值。

The most common concurrency problem I‘ve seen, is not realizing that a field written by one thread is not guaranteed to be seen by a different thread. A common application of this:

class MyThread extends Thread {
  private boolean stop = false;

  public void run() {
    while(!stop) {
      doSomeWork();
    }
  }

  public void setStop() {
    this.stop = true;
  }
}

As long as stop is not volatile or setStop and run are not synchronized this is not guaranteed to work. This mistake is especially devilish as in 99.999% it won‘t matter in practice as the reader thread will eventually see the change - but we don‘t know how soon he saw it.

以上是关于what's problem will you face in the multiple threading tasks的主要内容,如果未能解决你的问题,请参考以下文章

The SmSh Android App Will Change Your Life. It's Free For Now.

hdu 5618 Jam's problem again

poj 1681 Painter's Problem(高斯消元)

[CF414E]Mashmokh's Designed Problem

英语口语练习(not always estimating your status in other's hearts. you will lose yourself when you live

What's friendship?