Re: Threads Help



Hi,

On 11 Dec 2002 13:01:20 +0100
Stéphane Konstantaropoulos <stephanek brutele be> wrote:

Hello everyone,

I am stuck with my GTK app.

I want one callback to fire a new thread and to execute separately.
I use pthread_create() in the callback.

My problem is that when I recast the void* from the thread initial
function into a pointer to the object I need, the pointer is NULL, and
it segfaults when I write to it, obvious.

Any ideas?

Here are the bits of code that are concerned:

The event to catch:

static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer
data)
{
      lum_player_test(data);
      return FALSE;
}

- I know the delete event is not the best one here but I need to learn
more about events as I don't manage to catch key events yet, pfff.

Here I create the new thread:

void lum_player_test(gpointer player)
{
      pthread_create(&thread, NULL,
                                      lum_player_play,  player);
      return;
}

and this is the function where the thread inits:

void *lum_player_play(gpointer ptr)
{
      LumPlayer *player = NULL;
      player = ptr;
[...]

- And there "player" is NULL, after the cast, I tried to cast the GTK
way or simple C way, like this
      player = LUM_PLAYER(ptr);
or
      player = (LumPlayer*) ptr;

But to no avail, "player" is NULL, ptr isn't though, when we enter the
function!

I cant belive it. The ddd is good thing to investigate this. 
http://www.gnu.org/software/ddd/


Is there a problem with shared resources? Strange, the actual "player"
object is declared as a global variable and initialized in the main and
never freed, so it should still be there.

It is the first time I use threads in C, this is probably not the way to
use them...

I 'd like to use gthreads but I cannot find doc about them, so I stick
to POSIX threads, this should not be the problem here.

http://developer.gnome.org/doc/API/2.0/glib/glib-Threads.html


What do you think?

BTW, this is an experiment to embed MPlayer into a gtk widget, directly.

Thanks for helping,
-- 
   _ _ _
  / \ \ \
 / / \ \ \          (el greco)
 \/_ | S  \   Muy Mano,
  | \/    /         Muy Presa.
   \_  K /  http://users.aber.ac.uk/ssk01
      \  \



      Peeter Vois
http://my.tele2.ee/vois



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