template<typename T>
class lunchbox::LFQueue< T >
A thread-safe, lock-free queue with non-blocking access.
Typically used for caches and non-blocking communication between two threads.
Current implementation constraints:
- One reader thread
- One writer thread
- Fixed maximum size (writes may fail)
- Not copyable
Example:
#include <test.h>
#include <lunchbox/clock.h>
#include <lunchbox/lfQueue.h>
#include <lunchbox/thread.h>
#include <iostream>
#define RUNTIME 1000
{
public:
virtual ~ReadThread() {}
virtual void run()
{
uint64_t nOps = 0;
uint64_t nEmpty = 0;
uint64_t item = 0xffffffffffffffffull;
{
if( queue.getFront( item ))
{
TEST( item == nOps );
uint64_t item2 = 0xffffffffffffffffull;
TEST( queue.pop( item2 ));
TEST( item2 == item );
++nOps;
}
TEST( item + 1 == nOps );
++nEmpty;
}
std::cout << 2*nOps/time << " reads/ms, " << nEmpty/time
<< " empty/ms" << std::endl;
}
};
int main( int, char** )
{
ReadThread reader;
uint64_t nOps = 0;
uint64_t nEmpty = 0;
TEST( reader.start( ));
while( clock.getTime64() < RUNTIME )
{
while( queue.push( nOps ))
++nOps;
++nEmpty;
}
TEST( reader.join( ));
std::cout << nOps/time << " writes/ms, " << nEmpty/time << " full/ms"
<< std::endl;
return EXIT_SUCCESS;
}
Definition at line 42 of file lfQueue.h.