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); }
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); }
void get_items(queue & stk) { for (;;) { long id; bool got = stk.pop(id); if (got) { bool erased = data.erase(id); bool inserted = dequeued.insert(id); assert(erased); assert(inserted); ++pop_count; } else if (!running.load()) return; } }
void deallocate(void) { for (;;) { dummy * node; if (allocated_nodes.pop(node)) { bool success = working_set.erase(node); assert(success); fl.template destruct<true>(node); } if (running.load() == false) break; } dummy * node; while (allocated_nodes.pop(node)) { bool success = working_set.erase(node); assert(success); fl.template destruct<true>(node); } }
void add(void) { for (boost::uint32_t i = 0; i != nodes_per_thread; ++i) { int id = generate_id<int>(); working_set.insert(id); while (sf.push(id) == false) {} ++spsc_queue_cnt; } running = false; }
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; } }
void allocate(void) { for (long i = 0; i != operations_per_thread; ++i) { for (;;) { dummy * node = fl.template construct<true, bounded>(); if (node) { bool success = working_set.insert(node); assert(success); allocated_nodes.push(node); break; } } } }
bool get_element(void) { int data; bool success = sf.pop(data); if (success) { ++received_nodes; --spsc_queue_cnt; bool erased = working_set.erase(data); assert(erased); return true; } else return false; }
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); } }
void add_items(queue & stk) { for (long i = 0; i != node_count; ++i) { long id = generate_id<long>(); bool inserted = data.insert(id); assert(inserted); if (Bounded) while(stk.bounded_push(id) == false) /*thread::yield()*/; else while(stk.push(id) == false) /*thread::yield()*/; ++push_count; } }
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; } }
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; } }
void run(void) { running = true; thread reader(boost::bind(&spsc_queue_tester_buffering::get, this)); thread writer(boost::bind(&spsc_queue_tester_buffering::add, this)); cout << "reader and writer threads created" << endl; writer.join(); cout << "writer threads joined. waiting for readers to finish" << endl; reader.join(); BOOST_REQUIRE_EQUAL(received_nodes, nodes_per_thread); BOOST_REQUIRE_EQUAL(spsc_queue_cnt, 0); BOOST_REQUIRE(sf.empty()); BOOST_REQUIRE(working_set.count_nodes() == 0); }
bool get_elements(void) { boost::array<int, buf_size> output_buffer; size_t popd = sf.pop(output_buffer.c_array(), output_buffer.size()); if (popd) { received_nodes += popd; spsc_queue_cnt -= popd; for (size_t i = 0; i != popd; ++i) { bool erased = working_set.erase(output_buffer[i]); assert(erased); } return true; } else return false; }
void add(void) { for (unsigned i = 0; i != nodes_per_thread; ++i) { while(fifo_cnt > 10000) thread::yield(); int id = generate_id<int>(); working_set.insert(id); while (sf.enqueue(id) == false) { thread::yield(); } ++fifo_cnt; } }
void add(void) { boost::array<int, buf_size> input_buffer; for (boost::uint32_t i = 0; i != nodes_per_thread; i+=buf_size) { for (size_t i = 0; i != buf_size; ++i) { int id = generate_id<int>(); working_set.insert(id); input_buffer[i] = id; } size_t pushed = 0; do { pushed += sf.push(input_buffer.c_array() + pushed, input_buffer.size() - pushed); } while (pushed != buf_size); spsc_queue_cnt+=buf_size; } }