<< April 26, 2004 | Home | April 28, 2004 >>

Generating HTML From Code With Enscript

I've been talking about enscript a lot lately.

It just so happens that it can also generate HTML from source code, converting the <, & signs, etc., with syntax highlighting, in color if you want. Very handy for putting code snippets into blogs or other Web documents:

[weiqi@gao] $ enscript --color --language=html --output=Main.html Main.java

Thread Synchronization Puzzle

Take a look at the code below. Should Main finish immediately? Under Sun J2SE SDK 1.4.2_04 on Fedora Core 1 Linux it does. Under gij 3.3.2 (the JVM in GCC 3.3.2) it doesn't. Intuitively, the worker thread waits on lock, which is never notified, so worker should be waiting indefinitely. Right?

public class Main {
    public static void main(String[] args) {
        final Thread lock = new Thread();
        Thread worker = new Thread() {
            public void run() {
                synchronized (lock) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                    }
                }
            }
        };
        worker.start();
        lock.start();
    }
}