unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#30261: segfault on simultaneous initialization
@ 2018-01-26 17:24 Sheheryar Parvaz
  2018-01-26 23:41 ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Sheheryar Parvaz @ 2018-01-26 17:24 UTC (permalink / raw)
  To: 30261

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

If the initial call to scm_with_guile is on a thread and in the main
thread at the same time, a segmentation fault occurs.

    #include <pthread.h>
    #include <libguile.h>

    void* hello_world(void *arg) {
        scm_c_eval_string("(display \"Hello World!\")");
        scm_c_eval_string("(newline)");
    }

    void run_guile() {
        scm_with_guile(&hello_world, NULL);
    }

    int main(int argc, char **argv) {

        pthread_t th;
        int ret = pthread_create(&th, NULL, &run_guile, NULL);

        run_guile();
        pthread_join(&th, NULL);

        return 0;
    }

Here is a backtrace of the issue.

    #0  0x00007ffff7afd976 in scm_set_current_dynamic_state () from /usr/lib/libguile-2.2.so.1
    #1  0x00007ffff7b5faec in guilify_self_2 () from /usr/lib/libguile-2.2.so.1
    #2  0x00007ffff7b604b4 in scm_i_init_thread_for_guile () from /usr/lib/libguile-2.2.so.1
    #3  0x00007ffff7b604f9 in with_guile () from /usr/lib/libguile-2.2.so.1
    #4  0x00007ffff7281312 in GC_call_with_stack_base () from /usr/lib/libgc.so.1
    #5  0x00007ffff7b60918 in scm_with_guile () from /usr/lib/libguile-2.2.so.1
    #6  0x00000000004007a3 in run_guile ()
    #7  0x00007ffff7893568 in start_thread (arg=0x7ffff5ea8700) at pthread_create.c:465
    #8  0x00007ffff75cb52f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95


[-- Attachment #2: Type: text/html, Size: 2823 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30261: segfault on simultaneous initialization
  2018-01-26 17:24 bug#30261: segfault on simultaneous initialization Sheheryar Parvaz
@ 2018-01-26 23:41 ` Mark H Weaver
  2018-01-27  0:58   ` Sheheryar Parvaz
  0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2018-01-26 23:41 UTC (permalink / raw)
  To: Sheheryar Parvaz; +Cc: 30261

Hi,

Sheheryar Parvaz <skipper308@hotmail.ca> writes:
> If the initial call to scm_with_guile is on a thread and in the main
> thread at the same time, a segmentation fault occurs.

Yes, this is a known issue.  At present, Guile must be fully initialized
in one thread before it can be safely used from any other thread.
Furthermore, when loading modules, you must ensure that no other thread
attempts to load or use the same module while it's being loaded.  If
possible, please arrange to load all modules that your program will need
before accessing Guile from other threads.

We'd like to fix this at some point, but for various reasons it's a
non-trivial project.

     Thanks,
       Mark





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30261: segfault on simultaneous initialization
  2018-01-26 23:41 ` Mark H Weaver
@ 2018-01-27  0:58   ` Sheheryar Parvaz
  2018-01-27 20:27     ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Sheheryar Parvaz @ 2018-01-27  0:58 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: 30261@debbugs.gnu.org

[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]

Are there any decent workarounds for this? I considered scm_init_guile, however
according to the documentation, it is non-portable. For modules, I have no idea how
I would initialize them.
________________________________
From: Mark H Weaver <mhw@netris.org>
Sent: January 26, 2018 6:41 PM
To: Sheheryar Parvaz
Cc: 30261@debbugs.gnu.org
Subject: Re: bug#30261: segfault on simultaneous initialization

Hi,

Sheheryar Parvaz <skipper308@hotmail.ca> writes:
> If the initial call to scm_with_guile is on a thread and in the main
> thread at the same time, a segmentation fault occurs.

Yes, this is a known issue.  At present, Guile must be fully initialized
in one thread before it can be safely used from any other thread.
Furthermore, when loading modules, you must ensure that no other thread
attempts to load or use the same module while it's being loaded.  If
possible, please arrange to load all modules that your program will need
before accessing Guile from other threads.

We'd like to fix this at some point, but for various reasons it's a
non-trivial project.

     Thanks,
       Mark

[-- Attachment #2: Type: text/html, Size: 2263 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30261: segfault on simultaneous initialization
  2018-01-27  0:58   ` Sheheryar Parvaz
@ 2018-01-27 20:27     ` Mark H Weaver
  0 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2018-01-27 20:27 UTC (permalink / raw)
  To: Sheheryar Parvaz; +Cc: 30261@debbugs.gnu.org

Sheheryar Parvaz <skipper308@hotmail.ca> wrote:
> If the initial call to scm_with_guile is on a thread and in the main
> thread at the same time, a segmentation fault occurs.

Mark H Weaver <mhw@netris.org> wrote:
> Yes, this is a known issue. At present, Guile must be fully initialized
> in one thread before it can be safely used from any other thread.
> Furthermore, when loading modules, you must ensure that no other thread
> attempts to load or use the same module while it's being loaded. If
> possible, please arrange to load all modules that your program will need
> before accessing Guile from other threads.

Sheheryar Parvaz <skipper308@hotmail.ca> writes:
> Are there any decent workarounds for this? I considered
> scm_init_guile, however according to the documentation, it is
> non-portable. For modules, I have no idea how I would initialize them.

The usual approach is to initialize Guile before spawning any other
threads.  You can do this by calling 'scm_with_guile' early in your
'main', and then moving most of the contents of your 'main' into the
inner function that 'scm_with_guile' calls.

If there are modules that you'll need to load from your threaded code,
then load them before spawning any threads, from within the inner
function that 'scm_with_guile' calls.  From C, you can load modules with
'scm_c_resolve_module'.

      Mark





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-27 20:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26 17:24 bug#30261: segfault on simultaneous initialization Sheheryar Parvaz
2018-01-26 23:41 ` Mark H Weaver
2018-01-27  0:58   ` Sheheryar Parvaz
2018-01-27 20:27     ` Mark H Weaver

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).