<commit_before>#include "thread.hpp"
#include "assert.hpp"

#include "../base/logging.hpp"

#include "../std/chrono.hpp"
#include "../std/exception.hpp"

#if defined(OMIM_OS_ANDROID)
void AndroidThreadAttachToJVM();
void AndroidThreadDetachFromJVM();
#endif  // defined(OMIM_OS_ANDROID)

namespace threads
{
namespace
{
/// Prepares worker thread and runs routine.
void RunRoutine(IRoutine * routine)
{
#if defined(OMIM_OS_ANDROID)
  AndroidThreadAttachToJVM();
#endif  // defined(OMIM_OS_ANDROID)

  routine->Do();

#if defined(OMIM_OS_ANDROID)
  AndroidThreadDetachFromJVM();
#endif  // defined(OMIM_OS_ANDROID)
}
}  // namespace

/////////////////////////////////////////////////////////////////////
// Thread wrapper implementation
Thread::Thread() : m_routine(0) {}

Thread::~Thread() { Join(); }

bool Thread::Create(IRoutine * pRoutine)<commit_msg>[threads] Not explicitly joined threads are detached in dtor.<commit_after>#include "thread.hpp"
#include "assert.hpp"

#include "../base/logging.hpp"

#include "../std/chrono.hpp"
#include "../std/exception.hpp"

#if defined(OMIM_OS_ANDROID)
void AndroidThreadAttachToJVM();
void AndroidThreadDetachFromJVM();
#endif  // defined(OMIM_OS_ANDROID)

namespace threads
{
namespace
{
/// Prepares worker thread and runs routine.
void RunRoutine(IRoutine * routine)
{
#if defined(OMIM_OS_ANDROID)
  AndroidThreadAttachToJVM();
#endif  // defined(OMIM_OS_ANDROID)

  routine->Do();

#if defined(OMIM_OS_ANDROID)
  AndroidThreadDetachFromJVM();
#endif  // defined(OMIM_OS_ANDROID)
}
}  // namespace

/////////////////////////////////////////////////////////////////////
// Thread wrapper implementation
Thread::Thread() : m_routine(0) {}

Thread::~Thread()
{
  // @todo (ygorshenin@): in general, it's not a good practice to
  // implicitly detach thread since detached threads work in
  // background, consume system resources and make it hard to reason
  // about program. Thus, all places where Thread is instantiated
  // should be fixed to explicitly detach thread.
  if (m_thread.joinable())
    m_thread.detach();
}

bool Thread::Create(IRoutine * pRoutine)
{'fraction_non_alphanumeric': 0.1893939393939394, 'fraction_numerical': 0.000946969696969697, 'mean_word_length': 3.5053304904051172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2829523', 'n_tokens_mistral': 677, 'n_tokens_neox': 671, 'n_words': 157}