|
Boost : |
Subject: [boost] Building ThreadPool with boost::function in boost::lockfree::queue
From: Ryan Fogarty (ryan.fogarty.msece_at_[hidden])
Date: 2013-04-01 11:41:22
I am having trouble typedef-ing a lockfree::queue with boost::function as
the element for a ThreadPool class I am writing.
TestJobQueue1 below compiles fine while TestJobQueue2 compile fails. I am
using gcc 4.7.2 and boost_1_53_0.
void doSomething() {
std::cout << "Called doSomething\n";
}
typedef boost::function<void ()> FunctionType;
class TestJobQueue1 {
public:
typedef std::vector<FunctionType> FunctionArray;
TestJobQueue1() {
std::cout << sizeof(FunctionType) << std::endl;
FunctionType f(&doSomething);
FunctionArray funcArray;
funcArray.push_back(f);
std::cout << funcArray.size() << std::endl;
}
};
class TestJobQueue2 {
public:
typedef boost::lockfree::queue<FunctionType> QueueType;
TestJobQueue2() {
std::cout << sizeof(FunctionType) << std::endl;
FunctionType f(&doSomething);
QueueType funcQueue;
funcQueue.push(f);
}
};
>> g++ -c -I/usr/local/boost_1_53_0/include TestFunctionCompleteness.cpp
produces:
In file included from TestFunctionCompleteness.cpp:11:0:
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp: In instantiation
of class boost::lockfree::queue<boost::function<void()> >:
TestFunctionCompleteness.cpp:42:17: required from here
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp:79:1: error:
invalid application of sizeof to incomplete type
boost::STATIC_ASSERTION_FAILURE<false>
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp:83:1: error:
invalid application of sizeof to incomplete type
boost::STATIC_ASSERTION_FAILURE<false>
>> g++ -c --std=c++0x -I/usr/local/boost_1_53_0/include
TestFunctionCompleteness.cpp
produces:
In file included from TestFunctionCompleteness.cpp:11:0:
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp: In instantiation
of class boost::lockfree::queue<boost::function<void()> >:
TestFunctionCompleteness.cpp:42:17: required from here
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp:79:5: error:
static assertion failed: (boost::has_trivial_destructor<T>::value)
/usr/local/boost_1_53_0/include/boost/lockfree/queue.hpp:83:5: error:
static assertion failed: (boost::has_trivial_assign<T>::value)
Is boost::function somehow an incomplete type and not expected to work in
boost::lockfree::queue or is this a bug in the queue implementation? Can
anyone suggest a simple workaround?
Thank you,
Ryan Fogarty
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk