Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SDL和X11多线程致命IO错误 我试图用C++和SDL创建一个简单的多线程例子,如下面所示: #include <iostream> #include "SDL/SDL_image.h" #include "SDL/SDL.h" #include "SDL/SDL_thread.h" #include "X11/Xlib.h" #include "SDLAbstractionLayer.h" #include <string> using namespace std; SDL_Thread* thread = NULL; bool quit = false; int myThread(void* data) { while (!quit) { //caption animation SDL_WM_SetCaption ("Thread is running", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running.", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running..", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running...", NULL); SDL_Delay(250); } return 0; } int main(int argc, char* argv[]) { SDL_Surface* screen = init(640, 480, ""); XInitThreads(); Surface test("resources/image.png"); thread = SDL_CreateThread(myThread, NULL); SDL_Event event; while (!quit) { if(SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit = true; break; } fillScreen(screen, Surface::WHITE); applySurface(0, 0, test, screen); flip(screen); } } cleanUp(); SDL_KillThread(thread); return 0; }_C++_Multithreading_Sdl_X11 - Fatal编程技术网

SDL和X11多线程致命IO错误 我试图用C++和SDL创建一个简单的多线程例子,如下面所示: #include <iostream> #include "SDL/SDL_image.h" #include "SDL/SDL.h" #include "SDL/SDL_thread.h" #include "X11/Xlib.h" #include "SDLAbstractionLayer.h" #include <string> using namespace std; SDL_Thread* thread = NULL; bool quit = false; int myThread(void* data) { while (!quit) { //caption animation SDL_WM_SetCaption ("Thread is running", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running.", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running..", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running...", NULL); SDL_Delay(250); } return 0; } int main(int argc, char* argv[]) { SDL_Surface* screen = init(640, 480, ""); XInitThreads(); Surface test("resources/image.png"); thread = SDL_CreateThread(myThread, NULL); SDL_Event event; while (!quit) { if(SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit = true; break; } fillScreen(screen, Surface::WHITE); applySurface(0, 0, test, screen); flip(screen); } } cleanUp(); SDL_KillThread(thread); return 0; }

SDL和X11多线程致命IO错误 我试图用C++和SDL创建一个简单的多线程例子,如下面所示: #include <iostream> #include "SDL/SDL_image.h" #include "SDL/SDL.h" #include "SDL/SDL_thread.h" #include "X11/Xlib.h" #include "SDLAbstractionLayer.h" #include <string> using namespace std; SDL_Thread* thread = NULL; bool quit = false; int myThread(void* data) { while (!quit) { //caption animation SDL_WM_SetCaption ("Thread is running", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running.", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running..", NULL); SDL_Delay(250); SDL_WM_SetCaption("Thread is running...", NULL); SDL_Delay(250); } return 0; } int main(int argc, char* argv[]) { SDL_Surface* screen = init(640, 480, ""); XInitThreads(); Surface test("resources/image.png"); thread = SDL_CreateThread(myThread, NULL); SDL_Event event; while (!quit) { if(SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { quit = true; break; } fillScreen(screen, Surface::WHITE); applySurface(0, 0, test, screen); flip(screen); } } cleanUp(); SDL_KillThread(thread); return 0; },c++,multithreading,sdl,x11,C++,Multithreading,Sdl,X11,或者这个: XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0" after 113 requests (113 known processed) with 2 events remaining. 我正在使用Ubuntu13和Eclipse开普勒。我试着做了一些研究,但没有发现任何有用的东西 编辑:所以我更新了代码,添加了一个计数器和一些到处都是的cout's: int myThread(

或者这个:

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
  after 113 requests (113 known processed) with 2 events remaining.
我正在使用Ubuntu13和Eclipse开普勒。我试着做了一些研究,但没有发现任何有用的东西

编辑:所以我更新了代码,添加了一个计数器和一些到处都是的cout's:

int myThread(void* data) {
   while (!quit) {
      //caption animation
      SDL_WM_SetCaption ("Thread is running", NULL);
      SDL_Delay(250);

      cout << "Thread is running 1" << endl;

      SDL_WM_SetCaption("Thread is running.", NULL);
      SDL_Delay(250);

      cout << "Thread is running 2" << endl;

      SDL_WM_SetCaption("Thread is running..", NULL);
      SDL_Delay(250);

      cout << "Thread is running 3" << endl;

      SDL_WM_SetCaption("Thread is running...", NULL);
      SDL_Delay(250);

      cout << "Thread is running 4" << endl;
   }

   return 0;
}

int main(int argc, char* argv[]) {
   SDL_Surface* screen = init(640, 480, "");
   XInitThreads();

   Surface test("resources/image.png");
   thread = SDL_CreateThread(myThread, NULL);
   SDL_Event event;
   int count = 1;

   while (!quit) {
      if(SDL_PollEvent(&event)) {
         if (event.type == SDL_QUIT) {
            quit = true;
            break;
         }

         fillScreen(screen, Surface::WHITE);
         applySurface(0, 0, test, screen);
         flip(screen);

         cout << "finished iteration " << count++ << endl;
      }
   }
然后,在第二次运行之后:

finished iteration 1
finished iteration 2
Thread is running 1
Thread is running 2
XIO:  fatal IO error 0 (Success) on X server ":0.0"
      after 116 requests (116 known processed) with 0 events remaining.

如果有疑问,请在主线程上执行所有SDL操作


主要的例外是
SDL\u PostEvent()

啊,没关系。我刚刚收到一封电子邮件的回复,该邮件是我发给制作我下面教程的人的:

是的,这是我的应用程序中的bug,我正在SDL2.0教程中修复它。 查看SDL2.0多线程示例以获得修复。问题是SDL的 多个线程执行渲染,但渲染不起作用。因此,从另一个线程设置标题 不正常。在2.0教程中,渲染是在一个线程和控制台输出中进行的 这是另一种情况


程序是否在输出存在之前打印输出?是的,我在while循环中添加了一个计数器,在主线程和SDL创建的线程中添加了一些cout。它打印出几毫秒的成功活动,然后终止。在大多数情况下,我只是尝试了一点SDL多线程,但是的,我通常只把事情保持在主线程上。
finished iteration 1
Thread is running 1
XIO:  fatal IO error 0 (Success) on X server ":0.0"
      after 113 requests (113 known processed) with 0 events remaining.
finished iteration 1
finished iteration 2
Thread is running 1
Thread is running 2
XIO:  fatal IO error 0 (Success) on X server ":0.0"
      after 116 requests (116 known processed) with 0 events remaining.