예제 #1
0
int main ()
{
    // Use a simple count to simulate a barrier.
    pseudo_barrier_init(g_barrier, 2);

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

    // Wait until the step thread is stepping
    while (g_test < 1)
        do_nothing();

    // Create a thread to exit while we're stepping.
    std::thread thread_2(create_thread_func, &thread_1);

    // Wait until that thread is started
    pseudo_barrier_wait(g_barrier);

    // Let the stepping thread know the other thread is there
    g_thread_created = 1;

    // Wait for the threads to finish.
    thread_2.join();
    thread_1.join();

    return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: llvm-project/lldb
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;
}
예제 #3
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;
}
예제 #4
0
파일: main.cpp 프로젝트: emaste/lldb
int main ()
{
    // Don't let either thread do anything until they're both ready.
    pseudo_barrier_init(g_barrier, 2);

    // Create two threads
    std::thread thread_1(thread_func);
    std::thread thread_2(thread_func);

    // Wait for the threads to finish
    thread_1.join();
    thread_2.join();

    return 0;
}
예제 #5
0
int TestEvent()
{
    g_Event.Open();
    g_Event.Set();

    CTestRunnableEvent run;

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

    thread_1.Start();

    for (int i = 0; i < 100; i++)
    {
        if (i == 20
            || i == 40
            || i == 60
            || i == 80)
        {
            IZ_PRINTF("Event Set\n");
            g_Event.Set();
            izanagi::sys::CThread::Sleep(100);
        }
        else if (i == 10
            || i == 30
            || i == 50
            || i == 70
            || i == 90)
        {
            IZ_PRINTF("Event Reset\n");
            g_Event.Reset();
            izanagi::sys::CThread::Sleep(100);
        }

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

    IZ_PRINTF("Event Set\n");
    g_Event.Set();

    thread_1.Join();
    g_Event.Close();

    return 0;
}
예제 #6
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;
}