Skip to content

Deadlock in static fields initialization #321

Description

@l1cache

Because of cross references in static fields of some fj classes (e.g. Equal and LazyString) we can encounter a deadlock if we use it in parallel.
Consider the following code:

public void test() throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            sleep();
            Equal.anyEqual();
        });
        Thread thread2 = new Thread(() -> {
            sleep();
            LazyString.lines_();
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();
    }

    private void sleep() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Most of the times it just never ends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions