FC5: getpid in threads

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

 



Hello,

In the FC3 day the following program, linked to /lib/libthread.so, when
ran would return me three unique pid's, one for each thread.

In FC5, this does not seems to work.  /lib/libpthread.so is gone and I'm
forced to use /lib/tls/libpthread.so and this code does not work; I get
the same pid back for every thread, the pid of the main program.

I have several thousand lines of code which depend on a thread being
able to get it's own unique pid.  How do I fix or work around this???

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>

void *
print_msg(void *ptr)
{
     char *message;
     message = (char *)ptr;

     std::cout << "PID of "
     	<< message
	<< " "
	<< getpid()
	<< std::endl;
}

int
main(int argc, char *argv[])
{
     std::cout << "Main PID: " << getpid() << std::endl;

     pthread_t thread1;
     pthread_t thread2;

     char *message1 = "Thread 1";
     char *message2 = "Thread 2";

     int iret1;
     int iret2;

     iret1 = pthread_create(&thread1, NULL, print_msg, (void*)message1);
     iret2 = pthread_create(&thread2, NULL, print_msg, (void*)message2);

     pthread_join(thread1, NULL);
     pthread_join(thread2, NULL); 

     std::cout << "Thread 1 Returns: " << iret1 << std::endl;
     std::cout << "Thread 2 Returns: " << iret2 << std::endl;

     return(0);
}

:b!

Brian D. McGrew { brian@xxxxxxxxxxxxx || brian@xxxxxxxxxxxxxxxxxxx }
--
> CAUTION!!!  Do not read this email while waxxing the cat!


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux