zoukankan      html  css  js  c++  java
  • 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, 所以每次调用局部的线程内函数时, 加锁

    每天早上叫醒你的不是闹钟,而是心中的梦~
  • 相关阅读:
    时间比较
    syslog 协议及其在 SysLogHandler 中的使用
    获取 postgresql 的当前索引
    dns域名解析
    wireshark
    ctypes使用
    python模块signal
    ThreadPoolExecutor多线程异步执行
    异步进程 multiprocessing 模板
    redis常见错误
  • 原文地址:https://www.cnblogs.com/vintion/p/4116934.html
Copyright © 2011-2022 走看看