Added automatic detection of threads count

Possible solution for discussion in #165.