   Multithreaded Update and Render
  In my project, i am doing multithreading. The game update is done by a worker thread and the Game Render is done by the Main Thread. The update thread writes to Buffer 1 and the Game Render Thread reads from Buffer2. Once the render is done the buffers are swapped. Apparently, at the initial frame both the buffers have the same set of information. The update and the Render thread communicates throught the buffer manager. The Buffer Manager has the Buffer 1 and Buffer 2. Each Buffer contains an unique ID and the pointer to the structure which contains the Transformation, WorldViewProjectionMatrices. The update thread makes changes to the Transformation, WorldViewProjectionMatrices.In my project, i have 36 cubes rotating about Y. Without the multithreading, all the cubes rotates fine, but when i switch to the multi threading mode, only one cube is getting rotated and the rest of the cubes remains static. But when i put a break point in the Update thread, and press F5, at this time all the cubes are getting updated and rotated. But i dont know why it doesnt work when i run the project without any break points.  NodeInfo has the Transformation and WVP matrices. Each Cube inherits INode class which has the basic information like NodeInfo, position......//Game.cppvoid Game::UpdateScene(float dt){if( IsMultiThreaded() ){// Update camera movementm_pCamera->Update(dt);m_pThreadBufferManager->Buffer1->ClearBuffer();for ( unsigned int i = 0; i < m_pCubes.size(); i++ ){m_pCubes->SetUniqueID();m_pThreadBufferManager->Buffer1->m_BufferMessages.push_back(m_pCubes->GetNodeInfoPtr());}StartUpdate(m_pThreadBufferManager);}}void Game::RenderScene(){UpdateWorldViewProj();GetDevice()->ClearRenderTargetView(GetRenderTargetView(), D3DXCOLOR(0,0,0,0));if( IsMultiThreaded() ){for( unsigned int i = 0; i < m_pCubes.size(); i++ ){m_pCubes->Render();}}m_pText->DrawString();}//Update.cppDWORD WINAPI UpdateThread(LPVOID n){ThreadBufferManager* pBufferManager = (ThreadBufferManager*) n;for( unsigned int i = 0; i < pBufferManager->Buffer1->m_BufferMessages.size(); i++ ){INode::UpdateThis(g_tUpdateTimer.Tick(), pBufferManager->Buffer1->m_BufferMessages);}return DWORD(n);}void StartUpdate(ThreadBufferManager *pBufferManager){g_hThreadHandle[0] = CreateThread(NULL,0,UpdateThread,(LPVOID)pBufferManager,NULL,NULL);WaitForMultipleObjects(MAX_UPDATE_THREADS, g_hThreadHandle, TRUE, INFINITE);}I would like to know why the cubes are not getting update in the multithreaded mode when there is no break point. I am happy to provide more details if the above is not sufficient..... cheers :)
  First: please use [ source ] tags when posting code like that, so that it's readable.Quote:But when i put a break point in the Update thread, and press F5, at this time all the cubes are getting updated and rotated. But i dont know why it doesnt work when i run the project without any break points.I would bet that your problem is definately the synchronisation/buffer-swapping between the two threads -- you don't seem to have posted any code that coordinates the render thread and the update thread, can you post the section that ensures both threads are idle and swaps the buffers?[EDIT]Wait... is your main thread creating the update thread every frame, and then blocking until it completes?[EDIT #2]Quote:Each Buffer contains an unique ID and the pointer to the structure which contains the Transformation, WorldViewProjectionMatrices.If you're only buffering pointers to the data, then the data itself is actually still shared between the two threads, which means you've got a race condition.   ;  Yea the main thread creates the update thread ever frame......yeah I am buffering the pointers to the data....I have understood where i am going wrong.. thanks... I will get back and post the code once i am done with this... thanks (Y)