Page 1 of 1

SDL2 & SDL_Event.

Posted: Sun Jun 20, 2021 5:44 am
by wazzcob
Faced the need to use two event handlers.
Here's an example of a simple quick program (without any checks).

Code: Select all

#include <SDL2/SDL.h>
int main(int argc, char **argv)
{
  SDL_Window *window = SDL_CreateWindow("Hello World!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
  SDL_Event event;
  while(1)
  {
    while(SDL_PollEvent(&event))
    {
      if (event.type == SDL_QUIT)
      {
        atexit(SDL_Quit);
        return 0;
      }
    }
  }
  return 0;
}
But, let's say, I want to have two threads that process clicks, AT THE SAME TIME, that is, synchronously, that is (I can't find the word), so that BOTH threads work, and if I have an ESC output on the second thread, then in the first stream, the output by the cross should be triggered. Usually, one of the streams replaces the other and it turns out that either the cross is triggered or the button (depending on which part of the file is inserted this or that block of code).
I feel that I need to dig in the direction of thread, although I'm not completely sure. Any ideas?

Re: SDL2 & SDL_Event.

Posted: Sun Jun 20, 2021 6:15 am
by xizer
Everything is simple here - you just need to understand what multithreaded programming is and why it is needed and what tasks it solves. Read at least something about it.
Problem on this topic will take it off like a hand.

Re: SDL2 & SDL_Event.

Posted: Tue Jun 22, 2021 11:48 am
by wazzcob
xizer wrote: Sun Jun 20, 2021 6:15 am Everything is simple here - you just need to understand what multithreaded programming is and why it is needed and what tasks it solves. Read at least something about it.
Problem on this topic will take it off like a hand.
It was not needed. Everything that needs to be done without multithreading. But thanks anyway!