/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® one core |
Each table row shows performance measurements for this C gcc program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 500,000 | Make Error | 916 |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read thread-ring benchmark to see what this program should do.
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
/* The Computer Language Benchmarks Game * http://benchmarksgame.alioth.debian.org/ contributed by Alex Burlyga */ #define _GNU_SOURCE #include <pthread.h> #include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <inttypes.h> #define NUMBER_OF_THREADS 503 pthread_mutex_t cv_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cv_main = PTHREAD_COND_INITIALIZER; pthread_cond_t *cvs = NULL; uint32_t token = 0; uint32_t token_count = 1000; uint32_t threads_started = 0; uint32_t number_of_cpus = 0; void *thread_function(void *arg) { uint32_t thread_num = *(uint32_t *)arg; uint32_t next_thread_num = (thread_num + 1) % NUMBER_OF_THREADS; cpu_set_t cpu_mask; CPU_ZERO(&cpu_mask); CPU_SET(0, &cpu_mask); pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpu_mask); pthread_mutex_lock(&cv_mutex); while (1) { threads_started++; pthread_cond_signal(&cv_main); pthread_cond_wait(cvs+thread_num, &cv_mutex); token++; if (token == token_count + 1) { printf("%d\n", thread_num + 1); token++; pthread_cond_signal(cvs+next_thread_num); pthread_mutex_unlock(&cv_mutex); break; } else if (token > token_count + 1) { pthread_cond_signal(cvs+next_thread_num); pthread_mutex_unlock(&cv_mutex); break; } pthread_cond_signal(cvs+next_thread_num); } pthread_exit(NULL); } int main(int argc, char **argv) { int errno = 0; pthread_t *threads = NULL; uint32_t *thread_args = NULL; if (argc > 1) { token_count = strtol(argv[1], NULL, 0); } number_of_cpus = sysconf(_SC_NPROCESSORS_CONF); threads = (pthread_t *)malloc(sizeof(pthread_t)*NUMBER_OF_THREADS); if (threads == NULL) { perror("pthread_t array malloc"); exit(1); } memset(threads, 0, sizeof(pthread_t)*NUMBER_OF_THREADS); thread_args = (uint32_t *)malloc(sizeof(uint32_t)*NUMBER_OF_THREADS); if (thread_args == NULL) { perror("thread_args array malloc"); exit(1); } memset(thread_args, 0, sizeof(uint32_t)*NUMBER_OF_THREADS); cvs = (pthread_cond_t *)malloc(sizeof(pthread_cond_t)*NUMBER_OF_THREADS); if (cvs == NULL) { perror("cvs array malloc"); exit(1); } pthread_mutex_lock(&cv_mutex); for (uint32_t i = 0; i < NUMBER_OF_THREADS; i++) { *(thread_args + i) = i; errno = pthread_cond_init(cvs+i, NULL); if (errno) { perror("pthread_cond_init"); exit(1); } errno = pthread_create(threads+i, NULL, thread_function, (void *)(thread_args + i)); if (errno) { perror("pthread_create"); exit(1); } } while(threads_started < NUMBER_OF_THREADS) { pthread_cond_wait(&cv_main, &cv_mutex); } pthread_cond_signal(cvs); pthread_mutex_unlock(&cv_mutex); for (int i = 0; i < NUMBER_OF_THREADS; i++) { pthread_join(*(threads + i), NULL); } free(cvs); free(thread_args); free(threads); pthread_exit(NULL); }
Sun, 28 Apr 2013 00:29:24 GMT MAKE: /usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=native -pthread threadring.gcc-3.c -o threadring.gcc-3.gcc_run threadring.gcc-3.c: In function ‘main’: threadring.gcc-3.c:91:5: error: ‘for’ loop initial declarations are only allowed in C99 mode threadring.gcc-3.c:91:5: note: use option -std=c99 or -std=gnu99 to compile your code threadring.gcc-3.c:112:14: error: conflicting types for ‘i’ threadring.gcc-3.c:91:19: note: previous definition of ‘i’ was here threadring.gcc-3.c:112:5: error: ‘for’ loop initial declarations are only allowed in C99 mode make: [threadring.gcc-3.gcc_run] Error 1 (ignored) rm threadring.gcc-3.c 0.09s to complete and log all make actions COMMAND LINE: ./threadring.gcc-3.gcc_run 500000 MAKE ERROR