SDL多线程问题之--Unknown request in queue while dequeuing

编译通过, 运行多线程时出现如下问题:

[xcb] Unknown request in queue while dequeuing

[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called

[xcb] Aborting, sorry about that.

程退出


调试的时候可能会运行得正常, 


此处的原理显然是多线程冲突

解决:

1. 创建线程用SDL_CreatThread, 不要用pthread

2. 主要是共用资源的互斥问题造成:

        pthread_mutex_lock(&flock);
        SDL_DisplayYUVOverlay(bmp, &rect);
        pthread_mutex_unlock(&flock);

    pthread_mutex_lock(&flock);
    bmp  = SDL_CreateYUVOverlay(width, height, SDL_YV12_OVERLAY, screen);
    pthread_mutex_unlock(&flock);

两处加锁, 可用pthread的锁, 也可用SDL的锁


因为每个线程共用了全局的bmp, 所以每次调用局部的线程内函数时, 加锁

posted @ 2014-03-04 11:44  海滨银枪小霸王  阅读(928)  评论(0编辑  收藏  举报