   Multithreading vc++
  HI i'm a noobie and i'm trying multithreading for the first time. in my program if i thread the terrain rendering only the first frame is rendered but when its done without thread its getting updated but the frame rate is 25.how to call the threaded function inside the main loop. i can only give ResumeThread(terrain).i'm using directx API.   
  Moving thread to For Beginners.   ;Quote:HI i'm a noobie and i'm trying multithreading for the first time.Hi there. We all were/are ;)You should first understand multithreading and then try to implement what you've learned in your game.Multithreading doesn't magically make your program faster. It's possible that you have a bottleneck in your code that can be solved without adding multithreaded capabilities to your game. If you can be more specific we can help you do identify the problem and solve it.There are so many things that could be responsible for your slow code, so I'll take a guess:- Is your executable build using the "Release" configuration?- Are you using the Release runtimes of DirectX?- What are you drawing exactly? When does it slow down?- How many times are you calling Draw(Indexed)Primitive per frame?As for the DirectX part: Rendering should be done completely in one thread. Don't try to use the DirectX device in more than one thread or you will crash (or experience slowdowns if you've set the multithreaded flag on device creation).   ;Quote:Original post by svarvindHI i'm a noobie and i'm trying multithreading for the first time. [snip]i'm using directx API.If you're using D3D9, then you really don't want to do any sort of threading - D3D9 doesn't behave very well at all with multiple threads, you need to explicitly say you want a multithreaded device, it's quite slow, and there's still a few functions you need to call from your main thread.It's fine to use a second thread for e.g. loading resources into a chunk of memory, but the main thread will have to do the Lock(), copy and Unlock(). The main thread will still have to be processing window messages and rendering.   ;Quote:Original post by Evil SteveIf you're using D3D9, then you really don't want to do any sort of threading - D3D9 doesn't behave very well at all with multiple threads, you need to explicitly say you want a multithreaded device, it's quite slow, and there's still a few functions you need to call from your main thread.It's fine to use a second thread for e.g. loading resources into a chunk of memory, but the main thread will have to do the Lock(), copy and Unlock(). The main thread will still have to be processing window messages and rendering.Just out of curiosity and to slightly commandeer the thread, do you know if the same thing applies to OpenGL?   ;Quote:Original post by MikeTacularJust out of curiosity and to slightly commandeer the thread, do you know if the same thing applies to OpenGL?Google brings up This rather old thread, which says that OpenGL is not thread safe. I'd assume that you can run all OpenGL rendering from a thread other than the main thread if you wish, but all the calls need to come from the same thread (Unless you handle synchronisation yourself).Having said that, I've hardly used OpenGL, so I could be completely wrong [smile]   ;  I think a thread-safe implementation of OpenGL would come at the cost of at least some performance loss, as 'thread-safe' really only means that the implementation employs synchronization mechanisms under the hood, so you don't have to.   