Add automatic thread-recognation

Detect number of threads at runtime.