diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-02-01 17:39:20 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-02-01 17:39:20 +0100 |
commit | 5ac5b735b8cbc2bab60298ae93b381e88b00007f (patch) | |
tree | 3f4b7ff72d572259c9630aa7007eb214bf30345a /lf_fifo_test.c | |
parent | 0a6e6c9e4155fae6b39871caf9b69e5b4a74bdd1 (diff) | |
download | lock_free-5ac5b735b8cbc2bab60298ae93b381e88b00007f.zip lock_free-5ac5b735b8cbc2bab60298ae93b381e88b00007f.tar.gz |
Diffstat (limited to 'lf_fifo_test.c')
-rw-r--r-- | lf_fifo_test.c | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/lf_fifo_test.c b/lf_fifo_test.c index 7d6a165..13ec1f5 100644 --- a/lf_fifo_test.c +++ b/lf_fifo_test.c @@ -198,10 +198,76 @@ static void run_aggressive_push_pop(int threads_n, int nodes_n) free(params); } +static void run_interlaced_push_pop(int push_threads_n, int pop_threads_n, int nodes_n) +{ + int threads_n; + uint32_t i,j; + lf_fifo_t fifo; + struct timespec start, end; + pthread_t *threads; + thread_params_t *params; + + threads_n = push_threads_n + pop_threads_n; + threads = malloc( sizeof(pthread_t)*threads_n); + if (threads==NULL) _failure("threads malloc failure"); + params = malloc( sizeof(thread_params_t)*threads_n); + if (params==NULL) _failure("params malloc failure"); + + lf_fifo_init( &fifo); + + for(i=0; i<threads_n; i++) + { + params[i].fifo = &fifo; + params[i].n = nodes_n; + } + + clock_gettime(CLOCK_MONOTONIC, &start); + for(i=0; i<push_threads_n; i++) + { + if (pthread_create( &threads[i], NULL, aggressive_push, ¶ms[i])) + _failure("Failed to create push thread"); + } + for(; i<threads_n-1; i++) + { + if (pthread_create( &threads[i], NULL, aggressive_pop, ¶ms[i])) + _failure("Failed to create pop thread"); + } + for(i=0; i<threads_n-1; i++) + { + pthread_join( threads[i], NULL ); + } + if (pthread_create( &threads[threads_n-1], NULL, aggressive_pop, ¶ms[threads_n-1])) + _failure("Failed to create pop thread"); + pthread_join( threads[threads_n-1], NULL ); + clock_gettime(CLOCK_MONOTONIC, &end); + + for(i=0; i<push_threads_n; i++) + { + _check((params[i].n==nodes_n),"push n failure after aggressive push"); + if (params[i].nodes) free(params[i].nodes); + } + j = 0; + for(; i<threads_n; i++) + { + j += params[i].n; + if (params[i].nodes) free(params[i].nodes); + } + /* _check((j==(push_threads_n*nodes_n)),"poped nodes count failure"); */ + fprintf(stderr,"%d/%d\n",j,(push_threads_n*nodes_n)); + + /* report( "interlaced push-pop", (push_threads_n+pop_threads), nodes_n, time_diff( &start, &end )); */ + /* _check((fifo_length(&fifo)==(threads_n*nodes_n)),"fifo length failure after aggressive push"); */ + + free(threads); + free(params); +} + int main(int argc, char *argv[]) { - run_aggressive_push_pop(100,100000); - /* run_aggressive_push_pop(1,10); */ + printf("running...\n"); + + /* run_aggressive_push_pop(100,1000000); */ + run_interlaced_push_pop(10,10,10000000); printf("success\n"); |