0

I am writing a plugin that uses a GLEWMX context. The plugin loads the GLEWMX context under thread id (1). Then when I got to run something it runs that task under thread id (2). I have access to both thread ids.

Should I switch the active thread to thread (1) using std:thread so I can access and run things under that context? How do I do that

1 Answers1

1

Yes and no. Some libraries indeed are restricted to running on a single thread, and I'm assuming that GLEWMX is one of those. That indeed means you shouldn't be calling it from thread 2.

Yet when you need something done by thread 1, you can't switch "the active thread". On modern computers, you have several active threads anyway, so the fact that thread 2 is active doesn't even imply that thread 1 is passive.

The correct solution is to create a threadsafe work queue for thread 1. Thread 2 can then put work in, and thread 1 picks the work up when ready. Unfortunately there's no Standard Library support for this, you'll have to cobble one together yourself. Use std::condition_variable and .wait in thread 1.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • The issue I am having is my program Rhino is creating all these threads, and I only have access to the thread IDs, not sure how to access how the threads are orginally created to do a work queue, ... so I was thinking just calling something on that first thread, but that was a good response – Tom Brown Nov 05 '14 at 16:41