Ejemplo n.º 1
0
END_TEST


/*-----------------------------------------------------------------------
 * Once
 */

START_TEST(test_once)
{
    cork_once_barrier(once);
    static size_t  call_count = 0;
    static int  value = 0;

#define go \
    do { \
        call_count++; \
        value = 1; \
    } while (0)

    cork_once(once, go);
    fail_unless_equal("Value", "%d", 1, value);
    cork_once(once, go);
    fail_unless_equal("Value", "%d", 1, value);
    cork_once(once, go);
    fail_unless_equal("Value", "%d", 1, value);
    cork_once(once, go);
    fail_unless_equal("Value", "%d", 1, value);

    fail_unless_equal("Call count", "%zu", 1, call_count);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(test_threads_04)
{
    struct cork_thread  *t1;
    struct cork_thread  *t2;
    int  v1 = -1;
    int  v2 = -1;

    DESCRIBE_TEST;

    fail_if_error(t1 = cork_test_thread_new("test1", &v1, 1));
    fail_if_error(t2 = cork_test_thread_new("test2", &v2, 2));
    fail_if_error(cork_thread_start(t1));
    fail_if_error(cork_thread_start(t2));
    fail_if_error(cork_thread_join(t2));
    fail_if_error(cork_thread_join(t1));
    fail_unless_equal("Values", "%d", 1, v1);
    fail_unless_equal("Values", "%d", 2, v2);
}