help-gnu-emacs
[Top][All Lists]
Advanced

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

Running Emacs module in other thread


From: mrf
Subject: Running Emacs module in other thread
Date: Tue, 20 Jul 2021 12:34:42 +0300
User-agent: mu4e 1.5.8; emacs 27.2

hi,

I'm learning howto create dynamic emacs modules in C and I try to run my
module with

(make-thread (mymod-test))

and even I try to use pthread inside my module but without using join it
breaks my running emacs.

my code contain gtk main loop and this is my code:

///////////////////////////////////////////////////////////////////////////////
#include <emacs-module.h>
#include <gtk/gtk.h>

int plugin_is_GPL_compatible;

static emacs_value
Fmymod_test (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
{
  gtk_init (NULL, NULL);

  GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show_all (win);
  gtk_main ();

  return env->make_integer (env, 39);
}

void bind_fun (emacs_env *env, const char *fname, emacs_value fun)
{
  env->funcall (env,
                env->intern (env, "fset"),
                2,
                (emacs_value []) {
                  env->intern (env, fname),
                  fun
                }
                );
}

int emacs_module_init (struct emacs_runtime *ert)
{
  emacs_env *env = ert->get_environment (ert);

  emacs_value fun = env->make_function (env,
                                        0,
                                        0,
                                        Fmymod_test,
                                        "doc",
                                        NULL);

  bind_fun (env, "mymod-test", fun);
  return 0;
}

/* Local Variables: */
/* compile-command: "gcc -pthread -fPIC `pkg-config --libs --cflags gtk+-3.0` 
-shared mymod.c -o mymod.so && cp mymod.so ~/.emacs.d/library/" */
/* End: */



reply via email to

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