Hi, I'm writing a GUI application recently, and as GTK-IS-NOT-THREAD-SAFE, so, I have some code as below:

class epcTags
{
    EPCType epc;
    ulong times;

    this ()
    {
        times = 0;
    }
}

__gshared epcTags[] epcTagsArray;

/* Callback for a D module which has a backgroud thread running.*/
void epcReadCB(in EPCType epc)
{
    epcTags tag = new epcTags();
    tag.epc = epc;
    tag.times = 1;

    foreach (t; epcTagsArray) {
        if (t.epc == epc) {
            t.times++;
            return;
        }
    }

    epcTagsArray ~= tag;
}

/* GTK gui thread */
int _trytimes = 0;
extern(C) nothrow static int threadIdleProcess(void* data) {
	//Don't let D exceptions get thrown from function
    try {
        if (_isRFIDReading) {
            _ui.rfidProgress.pulse();
            /* put epc data to ui list */
            _ui.listTagStore.clear();
            foreach (tag; epcTagsArray) {
                TreeIter iter = _ui.listTagStore.createIter();
                _ui.listTagStore.setValue(iter, TAGLIST_COL1, bytesToHexStr(tag.epc));
                _ui.listTagStore.setValue(iter, TAGLIST_COL2, tag.times);
                _ui.listTagStore.setValue(iter, TAGLIST_COL3, false);
            }
            return 1;
        }
        else {
            return 0;
        }
	} catch (Throwable t) {
		return 0;
    }
}


mainGTKAppUILogic()
{
  ..........
  gdk.Threads.threadsAddIdle(&threadIdleProcess, null);
  ..........
}

The code actually works, but for me, I found it very strange, the threadIdelPRocss is something not D. and data will be passed using void * data, which is not D as well.

I tried to use the D lang signal/solt in STD-library, but, it's not suitable for gtk main thread as well. which i want to do is emit or send some msg in a clean GUI-less D thread, when data got, it tells the main gtk gui to display that data. using socket api to do such thing is a way, but it's another kind of complex.

So, is there a more idiomatic and simple way of doing this?

PS: why GtkD is not a kind thing like PyGI using the introspection kind of binding instead of using static binding ? AND I found the gernerated GtkD is not that valueable for a reference, all description is just copied from gtk-c document, it's useless. So when I learning to use something, what I did is just reading PyGtk3 tutorial and then find out is there a equal in GtkD, it's painfull. But, anyway, GtkD is useable. Thanks for the greate project.