Пример #1
0
static void*
startHook(void* arg)
{
    //
    // Ensure that the thread doesn't go away until run() has
    // completed.
    //
    IceUtil::ThreadPtr thread;

    try
    {
        IceUtil::Thread* rawThread = static_cast<IceUtil::Thread*>(arg);

        thread = rawThread;

        //
        // See the comment in IceUtil::Thread::start() for details.
        //
        rawThread->__decRef();
        thread->run();
    }
    catch(...)
    {
        if(!thread->name().empty())
        {
            consoleErr << thread->name() << " terminating" << endl;
        }
        std::terminate();
    }

    thread->_done();

    return 0;
}
Пример #2
0
static unsigned int
WINAPI startHook(void* arg)
{
    // Ensure that the thread doesn't go away until run() has
    // completed.
    //
    IceUtil::ThreadPtr thread;

    try
    {
        IceUtil::Thread* rawThread = static_cast<IceUtil::Thread*>(arg);

        //
        // Ensure that the thread doesn't go away until run() has
        // completed.
        //
        thread = rawThread;

        //
        // Initialize the random number generator in each thread on
        // Windows (the rand() seed is thread specific).
        //
        unsigned int seed = static_cast<unsigned int>(IceUtil::Time::now().toMicroSeconds());
        srand(seed ^ static_cast<unsigned int>(hash<thread::id>()(thread->getThreadControl().id())));

        //
        // See the comment in IceUtil::Thread::start() for details.
        //
        rawThread->__decRef();
        pthread_setname_np(thread->name().c_str());
        thread->run();
    }
    catch(...)
    {
        if(!thread->name().empty())
        {
            cerr << thread->name() << " terminating" << endl;
        }
        std::terminate();
    }

    thread->_done();
   
    return 0;
}