Hi Scuri,
Recently I tried to use IUP with more than one thread. My plan is simple,
run IupMainLoop() in one thread and feed progress bar or text control in
another thread. Theoretically I don't need to synchronize the IUP calls
because the IupMainLoop() will process the events sooner or later. However
I met a lot of problems. Sometimes the client area became invalided without
refresh. Sometimes I got a core dump triggered by X11 event. For example,
the attached file was simplified from my program. When the progress bar
running, if you select text in the text control, the app will received sig
11:
iqiup: Fatal IO error 11 (Resource temporarily unavailable) on X server
:0.0.
It looks like I misunderstood the programming model of IUP. Is IUP safe to
update the attribution of controls in different thread? If it's not, how
can I manually send events to the main loop to update the controls?
Kind regards
Andy
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <pthread.h>
#include "iup.h"
Ihandle *dlg_main;
Ihandle *tune_label_total;
Ihandle *tune_label_fail;
Ihandle *tune_progress;
/* gcc -Wall -g -I./external/iup/include `pkg-config gtk+-2.0 --cflags` -L./external/iup/lib/Linux311_64 -o iqtuner iqiup.cpp -lpthread -liup `pkg-config gtk+-2.0 --libs` -lX11
*/
static void *task_command(void *arg)
{
int i;
static char buf[64], tune_fail[64];
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
IupSetInt(tune_progress, "MIN", 0);
IupSetInt(tune_progress, "MAX", 99);
for (i = 0; i < 100; i++) {
IupSetInt(tune_progress, "VALUE", i);
sprintf(buf, "Frequency Tuned: %d", i);
IupSetAttribute(tune_label_total, "VALUE", buf);
sprintf(tune_fail, "Failure of Tuning: %d", i + 100);
IupSetAttribute(tune_label_fail, "TITLE", tune_fail);
sleep(1);
}
return NULL;
}
int main(int argc, char **argv)
{
pthread_t task_cmd;
Ihandle *vbox_tune;
IupOpen(&argc, &argv);
IupSetGlobal("SINGLEINSTANCE", "IQTuner");
tune_label_total = IupText(NULL);
IupSetAttribute(tune_label_total, "READONLY", "YES");
IupSetAttribute(tune_label_total, "BORDER", "NO");
IupSetAttribute(tune_label_total, "BGCOLOR", "DLGBGCOLOR");
IupSetAttribute(tune_label_total, "CANFOCUS", "NO");
IupSetAttribute(tune_label_total, "SIZE", "120");
tune_label_fail = IupLabel(NULL);
IupSetAttribute(tune_label_fail, "TITLE", "Failure of Tuning: 0");
tune_progress = IupProgressBar();
IupSetAttribute(tune_progress, "EXPAND", "HORIZONTAL");
IupSetAttribute(tune_progress, "SIZE", "x10");
IupSetAttribute(tune_progress, "DASHED", "YES");
vbox_tune = IupVbox(tune_label_total, tune_label_fail, tune_progress, NULL);
IupSetAttribute(vbox_tune, "NGAP", "8");
IupSetAttribute(vbox_tune, "NMARGIN", "8x8");
dlg_main = IupDialog(vbox_tune);
IupSetAttribute(dlg_main, "TITLE", "IQTuner");
IupSetAttribute(dlg_main, "RASTERSIZE", "500x400");
IupShow(dlg_main);
pthread_create(&task_cmd, NULL, task_command, NULL);
IupMainLoop();
pthread_cancel(task_cmd);
pthread_join(task_cmd, NULL);
IupDestroy(dlg_main);
IupClose();
return 0;
}
------------------------------------------------------------------------------
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users