Skip to content

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

@ggslove

Description

@ggslove

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

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions