Exemplo n.º 1
0
int main ()
{
    // The first barrier waits for the non-joining threads to start.
    // This thread will also participate in that barrier.
    // The idea here is to guarantee that the joining thread will be
    // last in the internal list maintained by the debugger.
    pseudo_barrier_init(g_barrier1, 5);

    // The second barrier keeps the waiting threads around until the breakpoint
    // has been passed.
    pseudo_barrier_init(g_barrier2, 4);

    // Create a thread to hit the breakpoint
    std::thread thread_1(break_thread_func);

    // Create more threads to slow the debugger down during processing.
    std::thread thread_2(wait_thread_func);
    std::thread thread_3(wait_thread_func);
    std::thread thread_4(wait_thread_func);

    // Create a thread to join the breakpoint thread
    std::thread thread_5(join_thread_func, &thread_1);

    // Wait for the threads to finish
    thread_5.join();  // implies thread_1 is already finished
    thread_4.join();
    thread_3.join();
    thread_2.join();

    return 0;
}
Exemplo n.º 2
0
int TestCondVar()
{
    g_Cond.Init();

    CTestRunnableCond_1 run_1;
    CTestRunnableCond_2 run_2;
    CTestRunnableCond_3 run_3;

    izanagi::sys::CThread thread_1(&run_1, IZ_NULL);
    izanagi::sys::CThread thread_2(&run_2, IZ_NULL);
    izanagi::sys::CThread thread_3(&run_3, IZ_NULL);

    thread_1.Start();
    thread_2.Start();
    thread_3.Start();

    for (;;)
    {
        if (g_IsLocked[0] && g_IsLocked[1] && g_IsLocked[2])
        {
            break;
        }
        izanagi::sys::CThread::YieldThread();
    }

    for (int i = 0; i < 100; i++)
    {
        if (i == 40)
        {
            IZ_PRINTF("Signal ********\n");
            g_Cond.Signal();
        }
        else if (i == 90)
        {
            IZ_PRINTF("Broadcast ********\n");
            g_Cond.Broadcast();
        }

        izanagi::sys::CThread::Sleep(100);
    }

    thread_1.Join();
    thread_2.Join();
    thread_3.Join();

    g_Cond.Destroy();

    return 0;
}
Exemplo n.º 3
0
int TestMutex()
{
    CTestRunnableMutex run;

    izanagi::sys::CThread thread_1(&run, IZ_NULL);
    izanagi::sys::CThread thread_2(&run, IZ_NULL);
    izanagi::sys::CThread thread_3(&run, IZ_NULL);

    thread_1.Start();
    thread_2.Start();
    thread_3.Start();

    for (int i = 0; i < 100; i++)
    {
        izanagi::sys::CThread::Sleep(10);
    }

    thread_1.Join();
    thread_2.Join();
    thread_3.Join();

    return 0;
}