Ejemplo n.º 1
0
    void run(void)
    {
        BOOST_WARN(stk.is_lock_free());

        running.store(true);

        thread_group writer;
        thread_group reader;

        BOOST_REQUIRE(stk.empty());

        for (int i = 0; i != reader_threads; ++i)
            reader.create_thread(boost::bind(&stack_tester::get_items, this));

        for (int i = 0; i != writer_threads; ++i)
            writer.create_thread(boost::bind(&stack_tester::add_items, this));

        using namespace std;
        cout << "threads created" << endl;

        writer.join_all();

        cout << "writer threads joined, waiting for readers" << endl;

        running = false;
        reader.join_all();

        cout << "reader threads joined" << endl;

        BOOST_REQUIRE_EQUAL(data.count_nodes(), 0);
        BOOST_REQUIRE(stk.empty());

        BOOST_REQUIRE_EQUAL(push_count, pop_count);
        BOOST_REQUIRE_EQUAL(push_count, writer_threads * node_count);
    }
Ejemplo n.º 2
0
    void add_items(void)
    {
        for (long i = 0; i != node_count; ++i)
        {
            long id = generate_id<long>();

            bool inserted = data.insert(id);
            assert(inserted);

            while(stk.push(id) == false)
                thread::yield();
            ++push_count;
        }
    }
Ejemplo n.º 3
0
void add_items(void)
{
    unsigned long count = 1000000;

    for (long i = 0; i != count; ++i)
    {
        thread::yield();
        long id = generate_id<long>();

        bool inserted = data.insert(id);

        assert(inserted);

        stk.push(id);
    }
}
Ejemplo n.º 4
0
    void get_items(void)
    {
        for (;;)
        {
            long id;

            bool got = stk.pop(&id);
            if (got)
            {
                bool erased = data.erase(id);
                assert(erased);
                ++pop_count;
            }
            else if (not running)
                return;
        }
    }
Ejemplo n.º 5
0
void get_items(void)
{
    for (;;)
    {
        thread::yield();
        long id;

        bool got = stk.pop(&id);
        if (got)
        {
            bool erased = data.erase(id);
            assert(erased);
        }
        else
            if (not running)
                return;
    }
}
Ejemplo n.º 6
0
 stack_tester(void):
     push_count(0), pop_count(0)
 {
     stk.reserve(128);
 }