O'Reilly logo

Mastering Android NDK by Viktor Latypov, Sergey Kosarevsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Portable multithreading primitives

The long-awaited std::thread from the C++11 standard is not (yet) available in MinGW toolchain at the time of writing, and it does not possess capabilities necessary to adjust thread priorities, which is important for networking. So, we implement a simple class iThread with the virtual method Run() to allow portable multithreading in our code:

class iThread
{

An internal LPriority enumeration defines thread priority classes:

public:
  enum LPriority
  {
    Priority_Idle         = 0,
    Priority_Lowest       = 1,
    Priority_Low          = 2,
    Priority_Normal       = 3,
    Priority_High         = 4,
    Priority_Highest      = 5,
    Priority_TimeCritical = 6
  };

The code for constructor and destructor is simple:

 iThread(): FThreadHandle( 0 ), FPendingExit( false ) {} virtual ~iThread() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required