bugGuile - Bugs: bug #20814, Issues with multithreading (using...

 
 

bug #20814: Issues with multithreading (using pthread, libguile 1.8.2)

Submitter:  None
Submitted:  Sat 18 Aug 2007 05:36:39 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 20 Aug 2007 09:34:56 AM UTC, comment #6: 

Hi,

Thanks for the reply.. now let's see...
Yes, the problem with the first example is indeed lack of guile mode in scm_test(), fixed by reworking it to call scm_init_guile() first, after which it enters a loop evaluating stuff, which just happily keeps on going. It works now, thanks.

You were right again on the second one, it works now too.

Thanks a lot for helping me out here.

Anonymous
Mon 20 Aug 2007 09:22:53 AM UTC, comment #5: 

Hi,

In your first example, the thread that executes `scm_test ()' is not in Guile mode (see `scm_with_guile'), hence the segfault I suppose.

In your second example, I suspect you have two initializations going in parallel.  I'd rather first call `scm_init_guile ()' and then call `guile_exec_thread ()'.  Can you tell us whether that fixes the problem?

Thanks,
Ludovic.

Ludovic Courtès <civodul>
Group administrator
Mon 20 Aug 2007 09:17:49 AM UTC, comment #4: 

Hi,

I've recompiled libguile from source (the original library I was using was part of Kubuntu's guile-libs package), removing the symbol size difference problem, so I suppose that's a bug with the lib I had originally installed and not a generic guile bug. The top snippet's behavior now mirrors the behavior of the bottom one , meaning it receives SIGSEGV after a while, but otherwise seems to be able to evaluate s-expressions just fine.

Anonymous
Mon 20 Aug 2007 08:48:10 AM UTC, comment #3: 

Hi

Of course, the simplest sample code that refuses to run is the following:
#include <libguile.h>
void* scm_test (void* l){
  SCM_TICK;
  scm_c_eval_string("(write (+ 6 5)) (newline)");
}

int main(int argc, char** argv){
  pthread_t blah;
  scm_init_guile();
  pthread_create(&blah, 0,scm_test,0);
  while(1)
    {
      SCM_TICK;
      scm_c_primitive_load("test.scm");
    }
}
This is running on Kubuntu GNU/Linux, here's the output of uname -a:
Linux zero-desktop 2.6.20-16-generic #2 SMP Thu Jun 7 20:19:32 UTC 2007 i686 GNU/Linux
Interestingly, the above sample code has a different problem, namely:
./a.out:
Symbol `scm_i_thread_key' has different size in shared object, consider re-linking
Segmentatiefout (core dumped)

The above might be a specific problem with my guile installation.

The other code with its amount of thread-safety issues (i.e. my original program with some guile additions), has a rather large amount of non-guile related code in it, so I'll omit that in the sample code for now, but, condensed, it'd come down to roughly:


void* guile_main(void* arglet){
  scm_shell(0,0);
}

void* run_guile(void* func){
  scm_with_guile(func,0);
}

pthread_t guile_exec_thread(void* func){
  pthread_t thread;
  pthread_create(&thread,NULL,run_guile,func);
}


int
main (int argc, char **argv)
{
  misc initialization
  guile_exec_thread(guile_main);
  scm_init_guile();
  while (1)
    {
      SCM_TICK;
      the body of a game's drawing loop (uses loads of OpenGL and other non-guile calls)
      scm_c_primitive_load("test.scm");
      sleep until the next frame
    }
  return 0;
}

I'll provide more information if necessary and for now, I'll recompile guile to see if that would fix my first problem.

Thanks for taking the time to discuss this.

Anonymous
Mon 20 Aug 2007 07:47:39 AM UTC, comment #2: 

Hi,

Can you please post sample code so that we have a clear idea of what you're doing?

Also, what platform is this on?

Thanks,
Ludovic.

Ludovic Courtès <civodul>
Group administrator
Sat 18 Aug 2007 08:15:59 PM UTC, comment #1: 

Just to clarify, the scm_* functions are called in a function called with scm_with_guile, so the threads calling scm_* functions are in guile mode.

Anonymous
Sat 18 Aug 2007 05:36:39 PM UTC, original submission:  

Hello,
I hope I haven't misinterpreted the Guile Reference Manual, Edition 1.1, but as I understand section 4.3.5 on using Guile with a multi-threaded C application, it would be possible to execute a program's main loop, written entirely in C, in one thread while running a Guile REPL in another thread while interpreting Guile scripts in another.

If I do try to do this or execute any scm_* functions in 2 threads at the same time, the result apparently is a segmentation fault, a stack overflow or, in case of attempting to use scm_spawn_thread in one thread to spawn the others, an error message stating "Function not implemented".

The latter error message seems to be exclusively related to use of scm_spawn_thread, whereas any of the rest of the list of errors accompanies any usage of scm functions in two threads simultaneously, even if such usage is merely "scm_c_eval_string("(+ 5 6)");".

I'd like to ask you if any of this is related to a bug with guile 1.8.2 or if what I'd like to do is as of yet impossible. If necessary, I'll clarify anything that needs clarification and if I'm wasting your time and misunderstood the manual, I apologize in advance.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by civodul (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-08-20 civodul Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.14-3b9d.
    Corresponding source code