Exemplo n.º 1
0
static void test_bidir_char_fifo(fifo& fc)
{
    check(fc.is_char_fifo());
    fc.enq("0123456789abcdefghijklmnopqrstuvwxy");
    fc.var_enq(variant('z'));
    fc.var_enq(variant("./"));
    check(fc.preview() == '0');
    check(fc.get() == '0');
    variant v;
    fc.var_deq(v);
    check(v.as_uchar() == '1');
    v.clear();
    fc.var_preview(v);
    check(v.as_uchar() == '2');
    check(fc.deq(16) == "23456789abcdefgh");
    check(fc.deq(memfifo::CHAR_ALL) == "ijklmnopqrstuvwxyz./");
    check(fc.empty());

    fc.enq("0123456789");
    fc.enq("abcdefghijklmnopqrstuvwxyz");
    check(fc.get() == '0');
    while (!fc.empty())
        fc.deq(fifo::CHAR_SOME);

    fc.enq("0123456789abcdefghijklmnopqrstuvwxyz");
    check(fc.deq("0-9") == "0123456789");
    check(fc.deq("a-z") == "abcdefghijklmnopqrstuvwxyz");
    check(fc.empty());
}
Exemplo n.º 2
0
    void run(void)
    {
        running = true;

        thread_group writer;
        thread_group reader;

        BOOST_REQUIRE(sf.empty());
        for (int i = 0; i != reader_threads; ++i)
            reader.create_thread(boost::bind(&fifo_tester::get, this));

        for (int i = 0; i != writer_threads; ++i)
            writer.create_thread(boost::bind(&fifo_tester::add, this));
        cout << "reader and writer threads created" << endl;

        writer.join_all();
        cout << "writer threads joined. waiting for readers to finish" << endl;

        running = false;
        reader.join_all();

        BOOST_REQUIRE_EQUAL(received_nodes, writer_threads * nodes_per_thread);
        BOOST_REQUIRE_EQUAL(fifo_cnt, 0);
        BOOST_REQUIRE(sf.empty());
        BOOST_REQUIRE(working_set.count_nodes() == 0);
    }