RE: [linux-audio-dev] problems creating/managing pthread stuff (audio-app related)

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: RE: [linux-audio-dev] problems creating/managing pthread stuff (audio-app related)
From: Ivica Bukvic (ico_AT_fuse.net)
Date: Thu Nov 22 2001 - 10:17:26 EET


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: owner-linux-audio-dev_AT_music.columbia.edu
[mailto:owner-linux-audio-dev_AT_music.columbia.edu] On Behalf Of Paul
Davis
Sent: Wednesday, November 21, 2001 3:03 PM
To: linux-audio-dev_AT_music.columbia.edu
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


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Thu Nov 22 2001 - 10:13:47 EET