http://stxxl.sourceforge.net
<beckmann@cs.uni-frankfurt.de>
http://www.boost.org/LICENSE_1_0.txt
#include <iostream>
#include <stxxl/mng>
#include <stxxl/bits/mng/read_write_pool.h>
#define BLOCK_SIZE (1024 * 512)
struct MyType
{
int integer;
char chars[5];
};
typedef stxxl::typed_block<BLOCK_SIZE, MyType> block_type;
int main()
{
stxxl::block_manager * bm = stxxl::block_manager::get_instance();
STXXL_DEFAULT_ALLOC_STRATEGY alloc;
{
STXXL_MSG("Write-After-Write coherence test");
stxxl::read_write_pool<block_type> pool(2, 10);
block_type * blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = pool.steal();
(*blk)[0].integer = 42;
pool.write(blk, bid);
blk = pool.steal();
pool.read(blk, bid)->wait();
delete blk;
blk = pool.steal();
(*blk)[0].integer = 23;
pool.write(blk, bid);
pool.hint(bid);
blk = pool.steal();
pool.read(blk, bid)->wait();
if ((*blk)[0].integer != 23) {
STXXL_ERRMSG("WRITE-AFTER-WRITE COHERENCE FAILURE");
}
pool.add(blk);
bm->delete_block(bid);
}
{
STXXL_MSG("Write-After-Hint coherence test #1");
stxxl::read_write_pool<block_type> pool(1, 1);
block_type * blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = pool.steal();
(*blk)[0].integer = 42;
pool.write(blk, bid);
blk = pool.steal();
pool.hint(bid);
(*blk)[0].integer = 23;
pool.write(blk, bid);
blk = pool.steal();
pool.read(blk, bid)->wait();
if ((*blk)[0].integer != 23) {
STXXL_ERRMSG("WRITE-AFTER-HINT COHERENCE FAILURE");
}
pool.add(blk);
bm->delete_block(bid);
}
{
STXXL_MSG("Write-After-Hint coherence test #2");
stxxl::read_write_pool<block_type> pool(1, 1);
block_type * blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = pool.steal();
(*blk)[0].integer = 42;
pool.write(blk, bid);
pool.hint(bid);
blk = pool.steal();
(*blk)[0].integer = 23;
pool.write(blk, bid);
blk = pool.steal();
pool.read(blk, bid)->wait();
if ((*blk)[0].integer != 23) {
STXXL_ERRMSG("WRITE-AFTER-HINT COHERENCE FAILURE");
}
pool.add(blk);
bm->delete_block(bid);
}
}