SDL2 & SDL_Event.

Programmers and people with programming knowledge sit here
Post Reply
wazzcob
Posts: 24
Joined: Fri Feb 05, 2021 5:11 am

SDL2 & SDL_Event.

Post 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?
User avatar
xizer
Posts: 87
Joined: Mon Oct 05, 2020 9:51 am

Re: SDL2 & SDL_Event.

Post 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.
wazzcob
Posts: 24
Joined: Fri Feb 05, 2021 5:11 am

Re: SDL2 & SDL_Event.

Post 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!
Post Reply