Skip to main content
added 204 characters in body
Source Link

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

1. Render Thread 2. Process Thread
- acquire lock and swap dataNew with dataDisplay, release lock
- render dataDisplay on the window
- read data
- process data
- acquire lock, copy data to dataNew buffer, release lock

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

Constraint - In my case, I have a pause option and also a time travel option to go back in frames to debug a particular frame if something is wrong there, so I cannot miss any frames for rendering

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

1. Render Thread 2. Process Thread
- acquire lock and swap dataNew with dataDisplay, release lock
- render dataDisplay on the window
- read data
- process data
- acquire lock, copy data to dataNew buffer, release lock

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

1. Render Thread 2. Process Thread
- acquire lock and swap dataNew with dataDisplay, release lock
- render dataDisplay on the window
- read data
- process data
- acquire lock, copy data to dataNew buffer, release lock

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

Constraint - In my case, I have a pause option and also a time travel option to go back in frames to debug a particular frame if something is wrong there, so I cannot miss any frames for rendering

Don't repeat tags in title. Don't hide text in images.
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Render and Process loop synchronisation with threads C++

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

enter image description here

1. Render Thread2. Process Thread
- acquire lock and swap dataNew with dataDisplay, release lock
- render dataDisplay on the window
- read data
- process data
- acquire lock, copy data to dataNew buffer, release lock

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

Render and Process loop synchronisation with threads C++

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

enter image description here

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

Render and Process loop synchronisation with threads

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

1. Render Thread2. Process Thread
- acquire lock and swap dataNew with dataDisplay, release lock
- render dataDisplay on the window
- read data
- process data
- acquire lock, copy data to dataNew buffer, release lock

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

Minor grammar fixes, markdown formatting
Source Link
liggiorgio
  • 5.5k
  • 6
  • 27
  • 38

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows : There.

There are two threads  :

enter image description here

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question  : In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for sometimesome time by design in general  ?

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows : There are two threads  enter image description here

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question  : In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for sometime by design in general  ?

I am developing an interactive visualizer for a project using Pangolin and OpenGL. The idea is as follows.

There are two threads:

enter image description here

Sample code:

// Render loop
while (!pangolin::ShouldQuit()) {
  if (mDataReadDone) break;

  // ....some code.....

  /*Critical section*/
  // Can acquire lock only after mDataNew 
  // is updated with new data in the process thread
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      std::swap(mDataDisplay, mDataNew);
  } /*Critical section*/

  // .....Render mDataDisplay data.........
}

// data process loop
while (!mWindowClosed) {
  // .....Read data....

  // .....Process data....

  // ....Copy data.....
  /*Critical section*/
  {
      std::unique_lock<std::mutex> lock(mRenderMutex);
      copyDataFromPipeline(mDataNew);
  }

}

Question: In the render loop, for the std::swap() to happen, it has to wait till new data is filled in mDataNew buffer by the process thread and hence the render loop is blocked for some time. Can the render loop be blocked for some time by design in general?

edited title
Link
Loading
Source Link
Loading