Sign in to follow this  

Assignment operator/copy constructor issue with Boost.Function

Recommended Posts

I've scoured the internet for hours on this one and still cannot figure it out! Any help is appreciated.

typedef boost::function<void ()> TaskKernel;
void TaskScheduler::pushTask(const TaskData& taskData, TaskKernel kernel)
Task* task = m_taskPool->obtain();
task->m_kernel = TaskKernel(kernel);
task->m_taskData = taskData;
// later in the calling code
sch->pushTask(TaskData(), boost::bind(&run);

I get an EXC_BAD_ACCESS in boost move_assign function for the copy constructor or operator= every time. I tried passing the function without boost::bind and with all different variations. No luck...

Is there a special technique I am missing for passing boost::functions around? Edited by Craig_jb

Share this post

Link to post
Share on other sites
Perhaps try changing this:

// task->m_kernel = TaskKernel(kernel);
task->m_kernel = kernel;

I haven't looked at the latest code for boost::function, but if it's doing move-emulation for your non-C++11 compiler, that might be causing trouble. If you really need the extra copy, try copying it to a [i]named[/i] temporary prior to the assignment (making the source of the assignment an l-value).

EDIT: perhaps you also intended to use pass-by-const-reference for the 'kernel' argument in pushTask()? Though I don't think that will cause this problem. Edited by e?dd

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this