Thanks for your help! As it turns out, I made a rudimentary mistake of
not declaring a static pointer to class correctly (actually I declared
it ok, but never made it point to the actual class, so when the method
was called by either thread or the main prog, the whole thing crashed.
Nonetheless, thanks for showing a very insightful way of implementing
the thread within the class! Sincerely,

Ivica Bukvic

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Paul
Davis
Sent: Wednesday, November 21, 2001 3:03 PM
To: [EMAIL PROTECTED]
Subject: Re: [linux-audio-dev] problems creating/managing pthread stuff
(audio-app related) 

[ pthread cry for help ... ]

1) buy a good book on programming with threads. i happen to like
   "Programming with Threads" by Kleiman, Shah & Smaalders, but there
   are others. You'll need it.

2) general method for using C++ objects when starting threads:

   class Foo {
     public:
       static void *function_called_by_thread (void *arg) {
         ((Foo *) arg)->actual_function_for_thread_to_run ();
       }
       
     private:
       void *actual_function_for_thread_to_run ();
   };

   
   pthread_t thread_id;
   Foo *myfoo;

   if (pthread_create (&thread_id, 0, 
                       Foo::function_called_by_thread, myfoo) != 0) {
       ... error: cannot create thread ...
   }

At this point, there is a new thread executing
Foo::function_called_by_thread(), which in turn will call
Foo::actual_function_for_thread_to_run().

Hope this helps.

--p


Reply via email to