Archive for the ‘multithreading’ tag
[French]Multithreading et Lecture du Clavier[/French][English]Multithreading and Keyboard Reading[/English]
[French]
La programmation multithreading est un monde à part et il faut bien en être conscient. Dans une des demos sur laquelle je bosse en ce moment,
il y a deux threads: le thread principal qui s’occupe de la gestion des messages de la fenêtre via la classique pompe à message GetMessage() et le thread de rendu pour le rendu 3D de la scène. Dans le thread de rendu, l’application a besoin de récupérer l’état des touches du clavier (pour controler la caméra) avec GetKeyboardState(). Mais la chose à savoir est que l’état du clavier et ses messages sont postés dans le thread principal qui gère la fenêtre et du coup le thread de rendu ne reçoit aucun message et donc ne peut pas lire le clavier avec et KeyboardState(). Une solution pour résoudre ce problème est de partager l’état du clavier entre les deux threads à l’aide de la fonction win32 AttachThreadInput():
[/French]
[English]
Multithreading programming is a world apart and you have to be aware of that fact. In one of my demos I’m working on, there are two threads:
the main thread that manages window messages via the usual GetMessage() based message pump and the render thread for rendering 3D stuff. In the render thread the app needs to retrieve the keyboard state (to control the camera) via GetKeyboardState(). The thing to know is that keyboard state and messages are posted to the main thread and the render thread can’t read keyboard state since this thread doesn’t receive keyboard messages. A way to solve this problem is to share keyboard state between both threads with the AttachThreadInput() win32 function:
[/English]
// === Main.cpp === // Main Thread DWORD main_thread_id = GetCurrentThreadId(); // === Render.cpp === // Render Thread DWORD render_thread_id = GetCurrentThreadId(); AttachThreadInput( render_thread_id, main_thread_id, TRUE );
[French]
Maintenant le thread de rendu peut lire l’état du clavier.
[/French]
[English]
Now the render thread can access to the keyboard state.
[/English]


