[lug] pthreads

Sebastian Sobolewski spsobole at mindless.com
Tue May 30 16:45:34 MDT 2000


         I've used pthreads in all a lot of my apps, many of them c++ 
programs.  By default gcc/g++ does not link in the pthreads lib.  You have 
to use the -lpthread option for it to compile.  When compiled  with this 
option you should not be getting a seg fault.  If you are then it's most 
likely the cause of some bad code/pointer.

here is a sniped of some pthread code I use:

// create a thread to handle irqs
//  irq_thread : is the thread handle.
//  irqHandler : see function below
//  this         :  void pointer to this class instance.  (optional parameter)
if(pthread_create(&irq_thread,NULL,(void *)&irqHandler,this)!=0){
         // handle error here

// The irqHandler function -- this function must be declared as "static"
//  header file declares this as:
//    static void irqHandler(void *);

void irqHandler(void *ptr){
                 // some code here

Perhaps if you pasted a sniped of your code I could be of more help.


At 02:15 PM 5/30/00 -0600, you wrote:
>I have a system running Caldera OpenLinux 2.2 and I am trying to implement a
>C++ program with threads.  I have included <pthread.h> at the top of the
>program, and when the program compiles I get the following message:
>aserv.o: In function `main':
>aserv.o(.text+0x215): undefined reference to `pthread_create'
>Based on the premise that a library wasn't being linked, I modified the gcc
>command to include the /usr/lib/libpthread.so, but I didn't think it would
>work (last resort, you know?).  It caused the above error to go away, but
>now I get a seg fault when trying to run the program -- right at the
>pthread_create.  I've looked the man and info pages and haven't found any
>specific secrets to make this work (to address the RTFM issue).
>Anyone have any clues?  Thanks.
>kevin at precisonline.com
>Web Page:  http://lug.boulder.co.us
>Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20000530/4d8b5196/attachment.html>

More information about the LUG mailing list