unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: mrf <joinlaw@cock.li>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Running Emacs module in other thread
Date: Tue, 20 Jul 2021 12:34:42 +0300	[thread overview]
Message-ID: <87pmvdxqzv.fsf@cock.li> (raw)


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	other threads:[~2021-07-20  9:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmvdxqzv.fsf@cock.li \
    --to=joinlaw@cock.li \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).