[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble: GTK + Octave + PThreads

From: John W. Eaton
Subject: Trouble: GTK + Octave + PThreads
Date: Wed, 4 Nov 1998 16:52:35 -0600 (CST)

On  4-Nov-1998, Rafael Laboissiere <address@hidden> wrote:

| [ Crossposting to gtk-list and help-octave]
| I am developing a GUI for Octave using GTK.  As it has to be launched
| from the Octave prompt, I avoid the "two main loops problem" (Octave's
| readline amd gkt_main) by using POSIX threads.  So the user can access
| internal Octave data either from the GUI and from the prompt.

Are you working on creating a set of programmable GUI objects that can
be used from Octave, or a GUI front end that would communicate with

I'm not sure why Posix threads would be needed.  Can't you just use
something like select() to decide where input is coming from?  With
Tcl/Tk and some other X-based GUI toolkits, it is relatively easy to
continue to get input from the readline prompt while also allowing the
GUI objects to function.  The readline library allows for this kind of
behavior.  For example, here is the code I used to do this sort of
thing with Tcl/Tk when I was playing around with the idea of using
that to implement a programmable GUI for Octave:

  // Compiled with:
  // g++ -o foo tkHelloWorld.c \
  //   -ltk4.2 -ltcl7.6 -lX11 -lreadline -ldl -lieee -lm -lc
  // and with the necessary -I and -L options to find the include and
  // library files.

  #include <iostream.h>

  #include <tcl.h>
  #include <tk.h>

  #include <readline/readline.h>
  #include <readline/history.h>

  extern "C" void
  do_nothing (ClientData, int)

  extern "C" int
  event_hook ()
    return Tcl_DoOneEvent (TCL_ALL_EVENTS);

  extern "C" void rl_deprep_terminal (void);

  clean_up_and_exit (ClientData)
    rl_deprep_terminal ();
    cout << "\n";
    exit (0);

  main (int argc, char **argv)
    rl_event_hook = event_hook;

    int retval = 0;

    Tcl_CreateExitHandler (clean_up_and_exit, 0);

    Tcl_Interp *interp = Tcl_CreateInterp ();

    Tcl_Init (interp);

    if (Tk_Init (interp) == TCL_ERROR)
        cerr << interp->result << "\n";

        retval = 1;
        Tk_CreateFileHandler (0, TK_READABLE, do_nothing, 0);

        bool done = false;

        while (! done)
            char *line = readline ("tk> ");

            if (line)
                if (*line)
                    add_history (line);

                    Tcl_Eval (interp, line);
              done = true;

    Tcl_DeleteInterp (interp);

    return retval;

| I am using GTK+ 1.1.2 (with appropriate gdk_threads_* calls), XFree86
| (thread safe), Octave 2.0.13 (recompiled with -D_REENTRANT),
| and LinuxThreads, as included in the GNU lic 2.0 (aka libc6).  I can
| send a minimal example to the nice soul willing to help me.

What does -D_REENTRANT do for complinig Octave?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]