I'm asking about linux with recent glibc.
Is there a way to detect that process consist of 1 thread or of several threads?
Threads can be created by pthread, or bare clone(), so I need something rather universal.
UPD: I want to detect threads of current process from it itself.
In taskmanager, right-click the game process and set the affinity to one core. Play a little ingame and check your fps. Then change affinity to two cores, if your fps increases then the game is (properly) multithreaded.
In the same multithreaded process in a shared-memory multiprocessor environment, each thread in the process can run concurrently on a separate processor, resulting in parallel execution, which is true simultaneous execution.
Every process has at least one thread, but there is no maximum number of threads a process can use. For specialized tasks, the more threads you have, the better your computer's performance will be. With multiple threads, a single process can handle a variety of tasks simultaneously.
Check if directory /proc/YOUR_PID/task/ contains only one subdirectory. If you have more than one thread in process there will be several subdirs.
The hardlink count can be used to count the subdirectories. This function returns the current number of threads:
#include <sys/stat.h>
int n_threads(void)
{
struct stat task_stat;
if (stat("/proc/self/task", &task_stat))
return -1;
return task_stat.st_nlink - 2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With