Commit 4f4e50b7 authored by T. Fischer's avatar T. Fischer

Keeping global variable for number of instanciated threads

parent a0aa079f
......@@ -82,6 +82,9 @@ char output_path[MAX_ARGUMENT_LENGTH];
/// variable is shared among threads, has to be protected by a mutex
int thread_id;
/// number of instanciated threads
int num_threads;
/// number of running threads, increased and decreased in each thread
/// variable is shared among threads, has to be protected by a mutex
int num_running_threads;
......@@ -256,7 +259,7 @@ void *run_command_function(void *x)
pthread_mutex_unlock(&workermutex);
char output_prefix[MAX_ARGUMENT_LENGTH];
snprintf(output_prefix, MAX_ARGUMENT_LENGTH - 1, "Thread %i", id);
snprintf(output_prefix, MAX_ARGUMENT_LENGTH - 1, "Thread %i/%i", id, num_threads);
char *full_command;
......@@ -345,8 +348,10 @@ int main(int argc, char *argv[])
output_path[1] = '\0';
be_verbose = 0;
be_silent = 0;
int num_threads = (int)(sysconf(_SC_NPROCESSORS_ONLN) & 0x0fffff);
const int num_physical_cores = (int)(sysconf(_SC_NPROCESSORS_ONLN) & 0x0fffff);
num_threads = num_physical_cores;
if (num_threads < 1) num_threads = 1;
if (num_threads > MAX_NUM_WORKER_THREADS) num_threads = MAX_NUM_WORKER_THREADS;
num_commands = 0;
int i;
for (i = MAX_NUM_COMMAND_LINES - 1; i >= 0; --i)
......@@ -407,8 +412,8 @@ int main(int argc, char *argv[])
num_commands = read_command_lines_file(argv[i], num_commands);
}
if (num_threads < 1 || num_threads > MAX_NUM_WORKER_THREADS)
num_threads = MAX_NUM_WORKER_THREADS;
if (num_threads < 1) num_threads = 1;
if (num_threads > MAX_NUM_WORKER_THREADS) num_threads = MAX_NUM_WORKER_THREADS;
if (be_verbose > 0) {
printf("num_commands=%i\n", num_commands);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment