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!

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux