Skip to main content

Well, you could use a separate threadthread to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threads than it has CPU cores (thread switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threads you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rarely and seemingly at random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?""When should I use a fixed or variable time step?".

Well, you could use a separate thread to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threads than it has CPU cores (thread switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threads you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rarely and seemingly at random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use a separate thread to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threads than it has CPU cores (thread switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threads you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rarely and seemingly at random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use a separate threatthread to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threatsthreads than it has CPU cores (threatthread switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threatsthreads you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rarerarely and seemingly at random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use a separate threat to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threats than it has CPU cores (threat switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threats you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rare and seemingly random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use a separate thread to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threads than it has CPU cores (thread switches are expensive), but also because it leads to bugs.

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threads you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rarely and seemingly at random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

added 179 characters in body
Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345

Well, you could use a separate threatsthreat to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threats than it has CPU cores (threat switches are expensive), but also because it leads to bugs. 

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threats you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rare and seemingly random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop, and which. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use threats to execute an object's update function in a loop, but that's a really bad idea. Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threats you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rare and seemingly random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop, and which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Well, you could use a separate threat to execute an object's update function in a loop, but that's a really bad idea. Not only will performance suffer when a system executes more threats than it has CPU cores (threat switches are expensive), but also because it leads to bugs. 

Adobe Flash executes the update-function of all objects at a controlled point of the application where the state of the rendering system is consistent. But with C++ timers and threats you would have no control over when that update is executed. When you have bad luck, one object reads data which another object is currently writing and reads a weird inconsistent state. This is called a race condition and leads to bugs which happen extremely rare and seemingly random, making them impossible to reproduce and debug. There are ways to deal with this, like semaphores, mutexes or critical sections, but they have their own pitfalls, like deadlocks.

Multithreading in C++ is a very advanced concept full of non-obvious problems. As a beginner you are well-advised to leave your hands off of it for now and write your game completely single-threaded.

The normal solution is to have a main thread which alternates between calling a global update() function and a global render() function. The global update() would then call the update-function of every object in the game in a for-loop. There are two ways to structure this main loop. Which one you pick is a rather religious question which is further elaborated on in the question "When should I use a fixed or variable time step?".

Source Link
Philipp
  • 123.2k
  • 28
  • 264
  • 345
Loading