Question

I have a multi-threaded application but sometimes one thread that is suppose to wake up after 10 seconds and do some work is not getting woken up from sleep or is starving.

It only happens sporadically.

//ACE task svc method
int svc (void)
    {
        while(true)
        {
            ACE_DEBUG((MY_INFO "sleep\n"));
            sleep(10);
            ACE_DEBUG((MY_INFO "awake for HB\n"));
            _csender.sendHeartBeat();
        }

        return 0;
    }

The last line in the log is: 2012-06-12 11:34:20.807272|INFO|sleep

Thread either didnt awake for 15 seconds or didn't do any work after its awaken until the 15th second, so the application closed.

There are total 6 threads in the application, all started with same priority. One of the thread is very busy, it receives a lot of market data and processes it, but does not send anything out on socket. The thread above is the only thread sending data out and both the receiver and sender threads are sharing the same socket object.

This is on red hat linux 5.3.

any ideas what could be the issue?

Was it helpful?

Solution

'Busy thread is prints 2 ACE_DEBUGs every 2 microseconds' - so probably clogging up the output queue of the debugger and preventing this thread from getting in to queue up its 'sleep\n'.

That, and/or you have prioritized down this thread and it cannot get a core, as other posters have indicated.

The sleep(10) is almost an irellevance.

OTHER TIPS

Sleep does not give any guarantees about maximum time spent sleeping, i.e. you sleep for at least that amount of time, or any time longer. I don't know if it's plausible to expect a 5 second delay though, sounds far too long.

I think its in ACE_DEBUG. Did you try a printf with a flush right after the sleep?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top