Re: pthreads question




  You should read a good c book -- the  C by K&R is a good one -- before you do
anything with pointers to function.

 This simply means that the function you supply must comply with the signature
-- which is:
  
  void *  (pointer to void) -- must be returned by the function.
  start_routine -- This is simply the name of the function you want the thread
to call when it is created and ready to run.

  void*  (pointer to void) must be the argument to the function.

  So, a function like this one can be used :

  void *my_function(void *){
    ...
  }

  So,
  pthread_create(..., ..., my_function, ...);

  is the correct way.

  Why pointer to void ??

   Well, this is the beauty and the demise ( depends on your perspective ) of
the C language..

  using this type of signature, you can pass and return anything you want to
and from your function..


  Notice that GTK uses a lot of pointer to functions -- especially in callbacks
-- so, you better understand how the syntax work:P)


Hope this helps.


Harring Figueiredo.


--- Thomas Deschepper <thomas deschepper tiscali be> wrote:
Yes, I know, this is a GTK-list, but because recently there were a lot
of posts about creating a worker thread and a thread managing the GUI, I
decided to start learning pthreads.

When a pthread is created with pthread_create(), you should pass in an
argument that defines the function you would like the thread to execute,
this is the 3rd argument.

void *(*start_routine) (void*)

Could someone please explain me this syntax?? Thanks in advance and
sorry if I offended you with a non-GTK-question!

mvg Thomas

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



        
                
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 



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