android - std::thread as member of class executing random thread causing an abort at asignate thread -


in class have thread object public membe:

class appmanager{    ...     public:     std::thread m_thread; }; 

then when initialize thread:

void* bridgefunction(void *pctx) {     ((appmanager*)pctx)->mainappthread();     return 0; }  void appmanager::createappthread(){    m_thread = std::thread(&bridgefunction, this);    m_thread.detach(); } 

i got abort on std::terminate:

 thread& operator=(thread&& __t) noexcept     {       if (joinable())       std::terminate();       swap(__t);       return *this;     } 

why? i'm calling detach, tried changing from:

m_thread = std::thread(&bridgefunction, this); 

to:

m_thread = std::thread(&appmanager::mainappthread, this); 

and same, works if declare m_thread global , debugged why works, turns out thread declared member execute random thread before assign thread, know because printed id see if joinable:

    auto myid = m_thread.get_id();     std::stringstream ss;     ss << myid;     std::string thread_id = ss.str();      logprintdebug("[thread activity] -  id of thread not created yet: %s", thread_id.c_str());      m_thread = std::thread(&bridgefunction, this);     m_thread.detach(); 

it prints:

[thread activity] - id of thread not created yet: 1074643408 

when declare global thread prints:

[thread activity] - id of thread not created yet::id of non-executing thread 

i printed id of actual thread , it's different id of random thread, try terminate due part:

if (joinable())  std::terminate(); 

i'm using visual studio 2015 running android native activity using clang 3.6 , gnu stl libraries, ndk r10e.

i tested same code on windows , id of thread 0, doesn't abort.

thanks


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -