Environment
- Android 5.0 @ Samsung Galaxy 5
- ADB @ Windows (x64)
- Native ADB Commandline tool
- C++11
Use-case
An application that creates a thread, detouch the created thread and exit the main thread
Problem description
The application process exit although the spawned thread was de-touched ( 'adb -d shell ps | findstr shell' shows no process running )
Code snippet
AddRef();
__android_log_print(ANDROID_LOG_INFO, "MySvc", "\n\nBefore thread start\n");
m_threadMainLoop = std::thread([this]() {
__android_log_print(ANDROID_LOG_INFO, "MySvc", "thread start\n");
HRESULT hr = m_spIOCP->DoModal();
OnCleanup(hr);
Release();
__android_log_print(ANDROID_LOG_INFO, "MySvc", "thread exit\n");
});
m_threadMainLoop.detach();
sleep(2);// w/o sleepping the will thread never start ( although it's detached )
__android_log_print(ANDROID_LOG_INFO, "MySvc", "After detach\n");
///////////////////////////////////////
// Main process thread will now exit //
///////////////////////////////////////
logcat output
I/MySvc( 5902): Before thread start
I/MySvc( 5902): thread start
I/MySvc( 5902): After detach
Aucun commentaire:
Enregistrer un commentaire