开发者

Small Linux application spawns SCHED_FIFO thread and sleeps. Long keypress locks the system

Running the code below (compiled with -lpthread) on a multicore system (Ubuntu 11.04 x86-32), which simply spawns a SCHED_FIFO thread and goes to sleep, displays some strange behavior. If you press a key it echoes it out just fine. However, if you hold down a key the process will hang and you will need to hard reboot (soft reboot hangs as does kill -9). Doing the same via a telnet session works just fine.

#include <sched.h>
#include <pthread.h>
#include <assert.h>

void* schedtest_busy_wait_thread_entry(void *arg)
{
    struct sched_param sp;

    sp.__sched_priority = sched_get_priority_min(SCHED_FIFO);
    assert(sched_setscheduler(0, SCHED_FIFO, &sp) == 0);
    while (1);
    return NULL;
}

int main(int argc, char **argv)
{
    pthread_t thread_id;

    assert(pthread_create(&thread_id, NULL, schedtest_busy_wait_thread_entry, NULL) == 0);
    while (1) sleep(1);
    return 0;
}

Obviously this is just an excerpt开发者_JAVA百科 of a much larger and more complex system that requires a busy waiting SCHED_FIFO thread (with hard coded affinity) but displays this same behavior. /proc/sys/kernel/sched_rt_runtime_us is at the default 950000.

Any pointers?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜