Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. C++11 Threads in Android Toolchain
QtWS25 Last Chance

C++11 Threads in Android Toolchain

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 3 Posters 5.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maurosanjo
    wrote on last edited by
    #1

    Hello,

    I'm trying to use an existing library developed in C++11, it uses std threads. I can't create a C++11 thread in a android app, when the thread constructor runs I get a seg fault error.

    My Tool Chain in Windows 7 is:
    Qt Creator 3.1.0
    Qt 5.2.1
    Android SDK for API 18 (Jelly)
    Android NDK r9d
    Deploying on Samsung Galaxy Note 10.1 2014 edition

    It compiles, and even can get the correct result for std::thread::hardware_concurrency().

    I tryed to set the flag: APP_CPPFLAGS = -std=c++11 and still same problem.

    Any ideas?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      Did you test your code on other platforms?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        s.frings74
        wrote on last edited by
        #3

        Multi-Threading depends on support by the Linux Kernel. Your application communicates to the kernel using the C libraries that are shipped as part of the Android operating system.

        Let me guess: The std libraries installed on the Android system are not compiled with C++11, so they don't support threads.

        It's possibly similiar to Java: A program that has ben compiled with Java 6 or 7 can run on Java 5 as long it does not use any of the new features.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maurosanjo
          wrote on last edited by
          #4

          Vincent: Yes the code is fine in other platforms.

          s.frings: Yes multi-threading depends on support on the kernel, but it does not mean they need to be compiled with C++11, it is not how it works. Android underlying kernel with no doubt has thread support.

          I believe the problem may lie on android NDK, some config flag that I'm not aware of. Thats what I'm asking :) My NDK toolchain is configured for GCC 4.8 and android-18.

          To test it out, one can simply create a foo method inside a class (could be the main form) and call the thread constructor like:

          std::thread newThread(&MyClass::FooMethod, this);

          it will crash inside the constructor, in my current configuration.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vincent007
            wrote on last edited by
            #5

            I saw someone encountered the same issue. Perhaps, it is a bug.

            You can try to use QThread instread of std thread.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maurosanjo
              wrote on last edited by
              #6

              Unfortunately I can't use Qt Threads in this module :/ At least not right now.
              It is maintained as a pure C++11 module, for reuse in other IDEs/Toolchains.

              I'm still testing, if anyone knows why it does not work.

              I found out that people are able to use std threads when using Android NDK, like "this":http://binglongx.wordpress.com/2013/04/07/c11-on-android/ or "this":http://stackoverflow.com/questions/20021527/android-ndk-r9b-and-compiling-c11

              But inside Qt Creator it is not working :/

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maurosanjo
                wrote on last edited by
                #7

                @std::thread t2(&MainWindow::ThreadAction, this, "Thread 2");@

                Using a class member function with one std::string parameter to create a thread, I reproduced the error and got two images, one with disassembler and other that shows std tuple line of code that occurs the segmentation fault.

                "ScreenShot1_disassembler":http://s16.postimg.org/vn5hlcclx/Qt_Print1.png

                "ScreenShot2_tupleError":http://s16.postimg.org/5uogrbowl/Qt_Print2.png

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maurosanjo
                  wrote on last edited by
                  #8

                  I found out the problem ¬¬

                  Due to an if clause misplaced the detach() was never called...

                  Always remeber to check for a call to join() or detach() ;)

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved