Example #1
0
int main()
{
    fiber_manager_init(NUM_THREADS);

    fiber_rwlock_init(&mutex);
    fiber_barrier_init(&barrier, NUM_FIBERS);

    fiber_t* fibers[NUM_FIBERS];
    int i;
    for(i = 0; i < NUM_FIBERS; ++i) {
        fibers[i] = fiber_create(20000, &run_function, NULL);
    }

    for(i = 0; i < NUM_FIBERS; ++i) {
        fiber_join(fibers[i], NULL);
    }

    fiber_barrier_destroy(&barrier);
    fiber_rwlock_destroy(&mutex);

    printf("try_rd %d try_wr %d count_rd %d count_wr %d\n", try_rd, try_wr, count_rd, count_wr);

    fiber_manager_print_stats();
    return 0;
}
Example #2
0
static void
fiber_cond_basic()
{
	struct fiber_cond *cond = fiber_cond_new();
	int check = 0;

	struct fiber *f1 = fiber_new("f1", fiber_cond_basic_f);
	assert(f1 != NULL);
	fiber_start(f1, cond, &check);
	fiber_set_joinable(f1, true);

	struct fiber *f2 = fiber_new("f2", fiber_cond_basic_f);
	assert(f2 != NULL);
	fiber_start(f2, cond, &check);
	fiber_set_joinable(f2, true);

	/* check timeout */
	fiber_sleep(0.0);
	fiber_sleep(0.0);

	/* Wake up the first fiber */
	fiber_cond_signal(cond);
	fiber_sleep(0.0);

	/* Wake ip the second fiber */
	fiber_cond_signal(cond);
	fiber_sleep(0.0);

	/* Check that fiber scheduling is fair */
	is(check, 2, "order");

	fiber_cond_broadcast(cond);
	fiber_sleep(0.0);

	fiber_join(f1);
	fiber_join(f2);

	fiber_cond_delete(cond);
}
Example #3
0
int main()
{
    fiber_manager_set_total_kernel_threads(NUM_THREADS);

    fiber_mutex_init(&mutex);

    fiber_t* fibers[NUM_FIBERS];
    int i;
    for(i = 0; i < NUM_FIBERS; ++i) {
        fibers[i] = fiber_create(20000, &run_function, NULL);
    }

    for(i = 0; i < NUM_FIBERS; ++i) {
        fiber_join(fibers[i]);
    }

    test_assert(counter == NUM_FIBERS * PER_FIBER_COUNT);

    return 0;
}