Pthreads + openGL + tcl = segfault!

I wrote a tcl package in C. This package uses linux threads (pthreads). If I load the package and at the same time use another package based on openGL (for example togl) I get segmentation fault. My system is running Gnu-Linux RedHat 7.3 and I use the nvidia drivers version 3123.
The tcl version is activetcl

Does anyone know if it is possible (and how) to combine multithreaded apps with openGL apps in tcl?

These are my attempts:

  • pthread with tcl: OK
  • openGL with tcl: OK
  • pthread with openGL (in C): OK
  • pthread and openGL in the same C app, but called from tcl: BAD!
  • pthread in one C app and openGL in another, but both called from tcl: BAD!
  • same thing but creating two different interpretes in tcl: BAD!

Thank you!


This is what I get using gdb:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 13175)]
0x409d4102 in glGetError () from /usr/lib/

or in other cases

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 13647)]
0x40337788 in __nvsym17113 () from /usr/lib/

and the backtrace:

#0 0x40337788 in __nvsym17113 () from /usr/lib/
#1 0x4015f710 in DTOR_END () from ./
#2 0x0805b0e8 in ?? ()
#3 0x080bc2c8 in ?? ()
Cannot access memory at address 0x2

Are you trying to access same OpenGL context form 2 different threads? I dont think that is possible (never tryed…but already read some about that). You will need to make one of the threads simply fire a signal to the other so that it caths it or pools it and only one thread touch at that context.

My two applications run independently, but one of them is supposed to run a tcl command defined by the other. But, beside all this, my problem is that I can’t even initialize the package. Let’s say pack_gl is the package using openGL and pack_pt is the one using pthreads: I do for example

% package require pack_gl
% pack_gl::create g
% g start # now the first app has started
% package require pack_pt

Then as soon as I click on the window opened by pack_gl, I get the segfault problem I described in the previous post. This without even creating and starting the object that uses threads. Note also that the order in which I call the "package require"s doesn’t matter in this respect. I also tried to remove everything from pack_pt, leaving only the bare initialization, and I get the same problem. It seems to me that just including <pthread.h> causes the problem.

You said you read about something similar before. Do you by any chance remember where? Or have any suggestion on a place where I could possibly find some more info?

Thank you very much


Some stuff I know about pthreads…

1 - by default, on Linux, new threads started by pthread_create() are joinable. If a pthread_join() is not performed on threads that are created as joinable, you can create memory leaks (stack problems I think).

2 - there are some problems that I have heard of when attempting to use pthreads and fork at the same time, forget where exactly, but it should be somewhere in the pthread docs if I’m not mistaken. Is the tcl program possibly using fork()?!

Couple of suggestions…

1 - nVidia has some newer drivers out for Linux, have you tried them yet?

2 - your one error you posted says “Cannot access memory at address 0x2” that means memory pointed to at the third byte of RAM, which is definately not where any of your program’s data, or the driver’s data should be. When you compile your libraries and executables, make sure you use the -g switch to gcc or g++, which ever one gets used. Those 0x080??? addresses should be memory addresses in use by your program, so they should not be named ?? if debugging symbols are on. That would help you find out which functions in your program are calling so you can set up watches to look at variables.


Thank you very much for your help,
I downloaded version 8.4.2 of tcl-tk and compiled it with the enable-threads flag. This solved the problem, even if I didn’t quite understand why. The previous version avaliable at my site was activetcl 8.4.1 and was compiled with the default settings (I guess without enable-threads). In spite of this my threaded application worked fine there too (if not in conjunction with an openGL app). This confused me on the need for the enable-threads flag.

Now everything is ok, and I’m not sure I want to spend time to understand what the different is between the two ways of compiling tcl-tk.

Thank you!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.