Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在 ch02中 VisibilityDemo实例为什么很难触发线程问题 #18

Open
ggslove opened this issue Feb 13, 2023 · 0 comments
Open

在 ch02中 VisibilityDemo实例为什么很难触发线程问题 #18

ggslove opened this issue Feb 13, 2023 · 0 comments

Comments

@ggslove
Copy link

ggslove commented Feb 13, 2023

按照代码,很难触发线程可见性问题,但是如果改为

public void run() {
        while (!ready) {
            count++;
        }
        if (ready) {
            System.out.println("---> 结束啦");
        }
    }

 public void cancel() {
        ready = true;
        System.out.println("cancel..");
    }

这样任务就不能停止了,然后-server 加不加都一样。应该是混合编译的问题吧。是不是原代码加了 Tools.randomPause,导致jit失效?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant