Question

I'm playing with gtkD for a while, and I'm learning D2/Phobos in parallel. Yesterday I was looking up the std.concurrency module and tried to write a toy multithreaded fractal viewer, but the problem is that I can't see the way multithreading works with gtkD.

Now, I have this:

import std.concurrency;

class TestMainWindow : MainWindow
{
    this() {
        super("test");
        ...
        spawn(&worker);
    }

    public void notify() {
        m_progress.pulse();
    }

    private ProgressBar m_progress;
}

shared(TestMainWindow) window;

main(string[] args) {
    Main.init(args);
    window = new shared(TestMainWindow)();
    Main.run();
}

void worker() {
    for (int i = 0; i < 20; ++i) {
        (cast(TestMainWindow) window).notify();
        Thread.sleep(dur!"msecs"(200));
    }
}

In the Andrei's book, in the chapter for concurrency, there's the message passing paradigm, which I want to apply, but the problem is that the gtk main loop is hidden from me. I don't like the above code, because its ugly to cast to non-shared and likely unsafe. So is there some way to inherit a "thread-agnostic" class, making it thread-aware, and what is the standard mechanism in gtkD to program multithreaded applications? I've seen the gthread.Thread module, but its role seems to be only as an interface to the external C gtk+ threading capabilities.

Was it helpful?

Solution

Unfortunately I'm pretty sure the answer is no. GtkD was designed before shared existed and supports both D1 and D2. Furthermore, shared is so buggy it's not usable yet. Therefore, GtkD doesn't support shared and probably won't for a while.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top