All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.tests.snippets.Synchronized Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.tests.snippets;

import static org.qbicc.runtime.CNative.*;

public class Synchronized {
    @extern
    public static native int putchar(int arg);

    public static void putbool(boolean val) {
        putchar(val ? 'T' : 'F');
    }

    public static void main(String[] args) throws InterruptedException {
        Object o1 = new Object();
        Object o2 = new Object();

        putbool(Thread.holdsLock(o1));
        putbool(Thread.holdsLock(o2));

        synchronized (o1) {
            putbool(Thread.holdsLock(o1));
            putbool(Thread.holdsLock(o2));
        }

        putbool(Thread.holdsLock(o1));
        putbool(Thread.holdsLock(o2));

        synchronized (o1) {
            synchronized (o2) {
                putbool(Thread.holdsLock(o1));
                putbool(Thread.holdsLock(o2));
            }
            putbool(Thread.holdsLock(o1));
            putbool(Thread.holdsLock(o2));
            synchronized (o1) {
                putbool(Thread.holdsLock(o1));
                putbool(Thread.holdsLock(o2));
            }
            putbool(Thread.holdsLock(o1));
            putbool(Thread.holdsLock(o2));
        }

        putbool(Thread.holdsLock(o1));
        putbool(Thread.holdsLock(o2));

        synchronized (o1) {
            putbool(Thread.holdsLock(o1));
            putbool(Thread.holdsLock(o2));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy