locked
How to build boost::thread for WinRT ARM?

    Question

  • Is it possible to use boost's thread library on WinRT on an ARM device? I built the boost library with the bootstrap command line utility, but that built x86 binaries. I tried to specify ARM with using

        b2 --with-thread architecture=arm

    But that gives me lots of errors.

    Then I tried to create a static lib project in VS2012, add the thread source files to it and compile to ARM, but I get compile errors like

        error C2065: 'TLS_OUT_OF_INDEXES' : undeclared identifier

    I have found here that TLS is not supported by WinRT, so that's why I'm getting the compile errors I guess.

    Does that mean that the x86 binary built by bootstrap uses the same illegal APIs, so my app wouldn't pass the Windows Store certification anyway?

    Is there some way to get around this limitation and build the boost::thread for WinRT ARM? (By the way I don't need the whole threading functionality, only shared_mutex and upgrade_lock.)


    • Edited by MarkVincze Tuesday, August 06, 2013 9:05 AM
    Monday, August 05, 2013 12:28 PM

Answers

  • Shortly, No.

    boost::recursive_mutex & boost::condition is dependent on boost::thread and  boost::thread uses some system APIs which is not allowed in Windows Runtime(WinRT). So you won't use it directly. If you use them you won't pass the app certification.

    You can use Windows synchronization function like Event, Mutex, Semaphore, CRITICAL_SECTION etc. and wrap up them according to your requirement.

    CRITICAL_SECTION CriticalSection; 
      
    InitializeCriticalSectionEx(&CriticalSection, 0, 0);
    
     // Request ownership of the critical section.
        EnterCriticalSection(&CriticalSection); 
    
        // Access the shared resource.
    
        // Release ownership of the critical section.
        LeaveCriticalSection(&CriticalSection);
    
    DeleteCriticalSection(&CriticalSection);

    • Marked as answer by MarkVincze Tuesday, August 06, 2013 9:03 AM
    Monday, August 05, 2013 2:19 PM

All replies

  • Shortly, No.

    boost::recursive_mutex & boost::condition is dependent on boost::thread and  boost::thread uses some system APIs which is not allowed in Windows Runtime(WinRT). So you won't use it directly. If you use them you won't pass the app certification.

    You can use Windows synchronization function like Event, Mutex, Semaphore, CRITICAL_SECTION etc. and wrap up them according to your requirement.

    CRITICAL_SECTION CriticalSection; 
      
    InitializeCriticalSectionEx(&CriticalSection, 0, 0);
    
     // Request ownership of the critical section.
        EnterCriticalSection(&CriticalSection); 
    
        // Access the shared resource.
    
        // Release ownership of the critical section.
        LeaveCriticalSection(&CriticalSection);
    
    DeleteCriticalSection(&CriticalSection);

    • Marked as answer by MarkVincze Tuesday, August 06, 2013 9:03 AM
    Monday, August 05, 2013 2:19 PM
  • I am currently using std::mutex with std::unique_lock, but that's causing some performance bottlenecks because I can't efficiently implement multipler readers/single writer with them, that's why I wanted the shared_mutex.

    My code base has to be compiled for WinRT, Windows desktop, Android and iOS, so I am trying to keep away from using platform-specific APIs, but then I might implement this section for each platform separately if necessary. 

    Thanks for the info!


    Tuesday, August 06, 2013 9:03 AM
  • I know this is over a year old, but if you are still interested in using Boost.Thread in WinRT I've made some changes that make it possible.

    http://blogs.msdn.com/b/vcblog/archive/2014/07/18/using-boost-libraries-in-windows-store-and-phone-applications.aspx

    Steve

    • Proposed as answer by Mark Vincze Tuesday, July 22, 2014 6:48 AM
    Monday, July 21, 2014 9:57 PM