Menu

Thread::getKey() returns rubbish on Solaris

Porting
2002-01-29
2002-02-07
  • Costas Kotsokalis

    Hello (again :))
    the following runs perfectly well on Linux, however it sigsegvs on Solaris after some loops. I have managed to trace the problem down to the pthread_getspecific call, which seems to return rubbish at some point (it does *NOT* return NULL, however the value returned is probably useless because when _parent->Notify() is called, the SIGSEGV takes place. Any ideas? Thanks!

    ---------------- Sample code ------------------
    #include <cc++/thread.h>

    #ifdef  CCXX_NAMESPACES
    using namespace std;
    using namespace ost;
    #endif

    #include <iostream>

    class MyThread : public Thread {
    public:
        MyThread();
        void Run();
    };

    MyThread::MyThread(){
        ;
    }

    void MyThread::Run(){
        cout << "THREAD" << endl;
        Exit();
    }

    int main(int argc, char *argv[]){
        while (1){
            MyThread m = MyThread();
            m.Detach();
            cout << "MAIN PROCESS" << endl;
            usleep(100);
        }
    }
    ---------------- Sample code ------------------

     
    • Frediano Ziglio

      Frediano Ziglio - 2002-01-30

      Why not joining cc++ stuff as porting developer ??

       
      • Frediano Ziglio

        Frediano Ziglio - 2002-01-30

        On compilefarm Solaris machine after 10000 loop (replaced while with for) nothing appened...
        Perhaps an error already fixed on CVS version (fixed recently)

         
      • Costas Kotsokalis

        I have been thinking about this lately :)
        Now as to the problem is concerned, I realise it always happens after 286 loops. *Always*. Could it be something that has to do with my system?

        From uname -a:
        SunOS myhost 5.7 Generic_106541-10 sun4u sparc SUNW,Ultra-5_10

        g++: 2.95.1

        Any ideas? Could it be some resource limit? Even if it is so, why does it apply sice all threads of execution Exit() normally?

        Thanks!

         
        • Costas Kotsokalis

          I forgot to mention that I already downloaded the latest CVS tree, and compiled/linked my software against it.

           
    • Costas Kotsokalis

      Ok I solved the problem, but I really can't understand what was wrong.

      Using a Final() method with the "delete this" hack, made it work like a charm. Yet, I thought there was no need to do that -- I thought using the Exit() method was enough. Is this normal behaviour? Am I missing something?

        Costas

       
      • Frediano Ziglio

        Frediano Ziglio - 2002-01-31

        Wait a moment...
        Try to remove Exit() inside Run...

         
        • Costas Kotsokalis

          I removed Exit() (and also removed Final()) and the problem still existed -- sigsegv after 286 loops. Only Final() (without Exit()) seems to solve it...

           
          • Frediano Ziglio

            Frediano Ziglio - 2002-02-07

            Ehmmm... after thinking so many...
            You detach thread, so Terminate (or destructor) can wait for thread end and destruct Thread object without waiting.
            So when thread exit sometime it found garbage...
            Solution is code like

            In MyThread::Final delete this

            Thread* th = MyThread();
            th->Detach();
            ... do other think
            DO NOT DELETE th...

            To found in linux I use printf for printing, remove wait in main and insert in MyThread::Run

            freddy77

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.