guile-user
[Top][All Lists]
Advanced

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

threads, muxes, gc, assert violation


From: Marco Maggi
Subject: threads, muxes, gc, assert violation
Date: Tue, 13 Mar 2007 07:32:45 +0100

Ciao,

  while running a test suite for a Guile (1.8.1) extension I
get:

  guile: ../../libguile/threads.c:1322:\
  scm_threads_mark_stacks: Assertion 't->top' failed.

it happens every  single time I run that  file in the suite.
My code creates *no* threads, it just prepares the following
interface for the foreign library to use:

  static scm_t * s_mutexes = NULL;

  /* begin of The Block */
  {
    int nmux = CRYPTO_num_locks();

    debug("requested %d mutexes", nmux);
    s_mutexes = scm_calloc(sizeof(scm_t) * nmux);
    for (int i=0; i<nmux; ++i)
      s_mutexes[i] = scm_permanent_object(scm_make_mutex());
  }
  /* end of The Block */

  /* -------------------------------------------------- */

  static void
  locking_function (int mode, int index,
                    const char * dummy_file, int dummy_line)
  {
    if (mode & CRYPTO_LOCK)
      scm_lock_mutex(s_mutexes[index]);
    else
      scm_unlock_mutex(s_mutexes[index]);
  }
  static unsigned long
  id_function (void)
  {
    return pthread_self();
  }

'locking_function()'  and 'id_function()' are  registered as
callbacks into the foreign  library and are invoked a number
of  times before  the  assertion is  violated.  The  foreign
library creates no threads by itself.

  The assertion is triggered by the GC run, I think, because
I can reproduce it when I explicitly call GC; but it happens
the second time I invoke GC.

  If  I   comment  out  The  Block   (excluding  the  thread
interface)  no  error is  raised.  If  I  replace the  Guile
threads interface with one that uses pthreads directly:

  static pthread_mutex_t * mutexes = NULL;

  {
    int nmux = CRYPTO_num_locks();

    debug("requested %d mutexes", nmux);
    mutexes = scm_calloc(sizeof(pthread_mutex_t) * nmux);
    for (int i=0; i<nmux; ++i)
      pthread_mutex_init(&(mutexes[i]), NULL);
  }

  /* -------------------------------------------------- */

  static void
  locking_function (int mode, int index,
                    const char * dummy_file, int dummy_line)
  {
    debug("enter: acting on %d, %d", index, (mode &
CRYPTO_LOCK));
    if (mode & CRYPTO_LOCK)
      pthread_mutex_lock(&(mutexes[index]));
    else
      pthread_mutex_unlock(&(mutexes[index]));
  }
  static unsigned long
  id_function (void)
  {
    return pthread_self();
  }

I get no error.

  Anyway, I do not see  why just (un)locking a mux can cause
such an error.

  Suggestions on how to debug it?


P.S.
Is there a way to extract the thread id from the thread SMOB
returned by 'scm_current_thread()'?

## --------------------------------------------------

0x401e25f1 in kill () from /lib/libc.so.6
#0  0x401e25f1 in kill () from /lib/libc.so.6
#1  0x401714e1 in pthread_kill () from /lib/libpthread.so.0
#2  0x401717eb in raise () from /lib/libpthread.so.0
#3  0x401e23a4 in raise () from /lib/libc.so.6
#4  0x401e38e8 in abort () from /lib/libc.so.6
#5  0x401dbab5 in __assert_fail () from /lib/libc.so.6
#6  0x400aa88d in scm_threads_mark_stacks () at
../../libguile/threads.c:1322
#7  0x40066b7e in scm_mark_all () at ../../libguile/gc-mark.c:82
#8  0x40066568 in scm_i_gc (what=0x400c4e56 "call") at
../../libguile/gc.c:594
#9  0x40066788 in scm_gc () at ../../libguile/gc.c:454
#10 0x4005c226 in deval (x=0x4062b158, env=0x403fbb40) at
../../libguile/eval.c:4122
#11 0x4005d56a in deval (x=0x4062b160, env=0x403fbb40) at
inline.h:250
#12 0x4005a5c8 in scm_dapply (proc=0x4062cf00, arg1=0x404,
args=0x403fbb58) at inline.h:250
#13 0x4005a703 in scm_apply (proc=0x4062cf70,
arg1=0x40343900, args=0x403262c8)
    at ../../libguile/eval.c:4796
#14 0x4006246f in scm_call_1 (proc=0x4062cf70, arg1=0x40343900)
    at ../../libguile/eval.c:4657
#15 0x4005af82 in scm_for_each (proc=0x4062cf70,
arg1=0x4062cf18, args=0x404)
    at ../../libguile/eval.c:5538
#16 0x4005c0d6 in deval (x=0x404, env=0x4062cf48) at
../../libguile/eval.c:4126
#17 0x40061961 in scm_i_eval_x (exp=0x6, env=0x4062cf48) at
inline.h:250
#18 0x4006256e in scm_primitive_eval_x (exp=0x4062ceb0) at
../../libguile/eval.c:5906
#19 0x400760d1 in scm_primitive_load (filename=0x403403f0)
at ../../libguile/load.c:109
#20 0x4005c0d6 in deval (x=0x404, env=0x405c44c0) at
../../libguile/eval.c:4126
#21 0x400618a8 in scm_i_eval (exp=0x6, env=0x405c44c0) at
inline.h:250
#22 0x4004eb92 in scm_start_stack (id=0x4062cf48,
exp=0x4031d970, env=0x405c44c0)
    at ../../libguile/debug.c:454
#23 0x4004ec10 in scm_m_start_stack (exp=0x4062cf48,
env=0x6) at ../../libguile/debug.c:470
#24 0x40059ef3 in scm_dapply (proc=0x403252a0,
arg1=0x4031d9a8, args=0x405c44c8)
    at ../../libguile/eval.c:4880

## --------------------------------------------------

--
Marco Maggi

"They say jump!, you say how high?"
Rage Against the Machine - "Bullet in the Head"





reply via email to

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