R: XForms: Threads and fl_get_input()

From: Enrico De Filippo (defilippo@lns.infn.it)
Date: Sun Feb 09 2003 - 08:21:07 EST

  • Next message: Steve Lamont: "Re: R: XForms: Threads and fl_get_input()"

    # To subscribers of the xforms list from "Enrico De Filippo" <defilippo@lns.infn.it> :

    Dear Steve,

    You are right; I was not clear in my mail and function fl_get_input()
    has nothing to do mith my problem that concerns mainly the fl_add_input
    object, i.e. an input box. To explain the problem I have included here
    your demo 'minput.c' in which I added a very simple thread that prints
    a message. If I use now XInitThreads() the process remain blocked when
    you try to give an input from keyboard (also
    if the thread continues to run well) and any interaction with the form
    is lost. If I comment XInitThreads() all run well. I am using XForms
    1.0Release on Linux RH 8.0 or 7.3 and compiling with:

    gcc -I/usr/X11R6/include/X11 -o minput minput.c -L/usr/X11R6/lib
    -lforms -lX11 -lm -lXpm -lpthread

    ps. the fact the in the example there is a multiline input field is only
    incidental. It is the same using a FL_NORMAL_INPUT

                                                    Enrico

    #include "forms.h"
    #include <stdio.h>
    #include <pthread.h>

    pthread_t tid;
    void *do_infinite_loop(void *);

    void input_cb(FL_OBJECT *ob, long data)
    {
        int x, y;
        fl_get_input_cursorpos(ob, &x , &y);
        fprintf(stderr,"x=%d y=%d\n",x,y);
    }

    int
    main(int argc, char *argv[])
    {
      FL_FORM *form;
      FL_OBJECT *but, *obj;

      XInitThreads();
      if(pthread_create(&tid, NULL, do_infinite_loop, NULL) !=0) {
       perror("pthread_create");
      }

      fl_initialize(&argc, argv, "FormDemo", 0, 0);
      form = fl_bgn_form(FL_UP_BOX,400,450);
        obj = fl_add_input(FL_MULTILINE_INPUT,30,270,340,150,"");
        obj = fl_add_input(FL_MULTILINE_INPUT,30,90,340,150,"");
        fl_set_object_lsize(obj, FL_NORMAL_SIZE);
      but = fl_add_button(FL_NORMAL_BUTTON,160,30,80,30,"Exit");
      fl_end_form();

      fl_show_form(form,FL_PLACE_CENTERFREE,FL_FULLBORDER,"MultiLineInput");

      do obj = fl_do_forms(); while (obj != but);

      fl_finish();
      return 0;
    }

    void *do_infinite_loop(void *nothing)
    {
     while(1) {
      sleep(2);
      puts("I am in a thread");
     }
    }

    -----Messaggio originale-----
    Da: owner-xforms@bob.usuhs.mil [mailto:owner-xforms@bob.usuhs.mil]Per
    conto di Steve Lamont
    Inviato: sabato 8 febbraio 2003 20.02
    A: xforms@bob.usuhs.mil
    Oggetto: Re: XForms: Threads and fl_get_input()

    # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :

    > Unfortunately, if I insert this, when I call fl_get_input() (to
    > insert a number or a string from keyboard) from a forms that is
    > managed my the main program (not by the thread) the program is
    > definitively blocked. What is wrong? Is there something to do before
    > calling fl_get_input()? The error is not present if I eliminate
    > XInitThreads();

    fl_get_input() is used to query the contents of an Input object's
    field. It should return more or less instantly.

    Are you referring to fl_show_input(), which pops a dialog box and
    requests input?

    By "blocked" do you mean that activity in all the threads ceases?

    I'm not sure why this would happen. The main loop of fl_show_input()
    looks like this

        do
        {
            retobj = fl_do_only_forms();
        }
        while (retobj != fd_input->ok && retobj != fd_input->cancel);

    and fl_do_only_forms() isn't that much different than fl_do_forms().

                                                            spl

    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/

    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Sun Feb 09 2003 - 08:15:28 EST