I posted this a couple of days ago but not sure what happened to the original
or any replies due to mail problems & master etc.

I have a demo program which I have included below which should do
some threads, in a C++ program. It works fine on Solaris 5.6,
it works fine on bo with libc5, but on both my libc6 systems
it segfaults, and gdb says that's in pthread_mutex_lock which
sounds weird to me. Any ideas?


thanks,
hamish


#include <iostream.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

const bool FALSE = 0;
const bool TRUE = 1;

class Server {
private:
    pthread_t threadid;
    bool active;

public:
    Server();
    ~Server() {
      if (active == TRUE) {
        cout << "we are screwed" << endl;
        cout.flush();
      }
      cout << "destroying " << threadid << endl;
      cout.flush();
    }
    static void *Server_main(void *);
};

Server::Server()
{
    active = FALSE;
    int retVal = pthread_create(&threadid, NULL, Server::Server_main, this);
    if (retVal == -1) {
      perror("Server");
    }
    cout << "retVal = " << retVal << " threadid " << threadid << endl;
}

void *Server::Server_main(void *param)
{
    Server *server = (Server *) param;

    server->active = TRUE;
    cout << "Server created threadid " << server->threadid << endl;
    cout << "exiting thread " << endl;
    cout.flush();
    sleep(2);
    server->active = FALSE;
    return 0;  // to shut up the compiler about returning values
}

int main()
{
    cout << "About to start a server" << endl;
    Server newserver;

    sleep(1);
    cout << "exiting main" << endl;
    return(0);
}


-- 
Hamish Moffatt       Mobile: +61 412 011 176       [EMAIL PROTECTED]

Rising Software Australia Pty. Ltd. 
Developers of music education software including Auralia & Musition.
31 Elmhurst Road, Blackburn, Victoria Australia, 3130
Phone: +61 3 9894 4788  Fax: +61 3 9894 3362  USA Toll Free: 1-888-667-7839
Internet: http://www.rising.com.au/


--
E-mail the word "unsubscribe" to [EMAIL PROTECTED]
TO UNSUBSCRIBE FROM THIS MAILING LIST. Trouble? E-mail to [EMAIL PROTECTED]

Reply via email to