pthreads and gtk 1.2
- From: WPD mestrole <mestrole easynet fr>
- To: gtk-list redhat com
- Subject: pthreads and gtk 1.2
- Date: Thu, 07 Oct 1999 17:29:26 +0200
Hie
I want to grab stdout and stderr to display it in a GtkText.
I want to be able to do it even if the gtk_main loop is deactivated
(so I think I can't use gtk_timout_add to do it)
a piece of my code :
GtkWidget * text;
GtkWidget * window;
void * Thr (*void)
{
char buf_err[BUFSIZ];
char buf_out[BUFSIZ];
char B[BUFSIZ];
int n;
setbuf(stdout,buf_out);
setbuf(stderr,buf_err);
while(1)
{
if (buf_out[0]!=0)
{
fflush(stdout);
sprintf(B,"%s",buf_out);
n=0;
while(B[n]!=0){
gtk_text_insert(GTK_TEXT(text),NULL,NULL,NULL,B+n++,1);}
}
if (buf_err[0]!=0)
{
fflush(stderr);
sprintf(B,"%s",buf_err);
n=0;
while(B[n]!=0){
gtk_text_insert(GTK_TEXT(text),NULL,NULL,NULL,B+n++,1);}
}
usleep(10000);
}
return NULL;
}
int main(void)
{
pthread_t pth;
int H;
... creation of the window and the gtktext...
gtk_widget_show(window);
pthread_create(&th,NULL,(void*)Thr,*void);
printf(" 1st section\n");
H=gtk_timeout_add(.... // display values of some external captors
printf(" 2nd section\n");
...
}
but it doesn't react very well: everything is blocked before displaying
the window with this code.
If I remove the setbuf(stderr,...) I can see 1st section on the terminal
and on the gtktext, but 2nd section only on the terminal... But not
everytime... and I get sometimes Xlib message : " sync failed ".
If I use this code replacing gtktext by a redirection to a logfile,
everything is correct.
(the pthread how-to says : with linux <2.1.x, Xlib use the two SIGUSR,
so can't use pthreads; but I do it with RTlinuxV2b12 base on kernel
2.2.10 that have much more free SIGUSR! don't understand...)
How could I get a stable processus, something doing what I want
everytime??
need help!!!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]