Hello I have to use parallel tasks for my application.
This involves creating a command line process and parsing a file created by the said process every half a second.
Before starting the gtk loop, I initiated GDK:
// main.d
import gdk.Threads : threadsInit;
threadsInit();
return app.run(args);
Now before and after running the parallel process I'm entering and leaving the thread:
// ui.d
trigger.addOnClicked(delegate void(Button _) {
deactivateInputs();
scope (success)
activateInputs();
progressBoxRevealer.setRevealChild(true);
auto sourceFileName = fcb.getFilename();
auto deviceName = parseDeviceName(deviceCombo.getActiveText());
import gdk.Threads : threadsEnter, threadsLeave;
threadsEnter();
auto ddCall = new Calldd(sourceFileName, deviceName);
import std.parallelism : task, Task;
auto proc = task(&ddCall.dd);
proc.executeInNewThread();
while ((!proc.done))
{
import glib.Timeout : Timeout;
import gtkc.gtktypes : GPriority;
auto timeout = new Timeout(500, delegate bool() {
auto percentage = ddCall.parse();
if (percentage == 0.0)
{
progress.pulse();
}
else if (percentage == 100.0)
{
return false;
}
else
{
progress.setFraction(percentage);
}
return true;
}, GPriority.HIGH);
}
threadsLeave();
});
}
Yet the whole app, in fact freezes. Any hint?
If you are interested the whole project (pretty small) is here
https://gitlab.com/9898287/nixwriter/tree/master/source