Opened 8 years ago

Last modified 6 years ago

#10878 assigned Feature Requests

boost::thread::attributes -> no non-variadic-support

Reported by: a.carot@… Owned by: viboes
Milestone: To Be Determined Component: thread
Version: Boost 1.57.0 Severity: Problem
Keywords: thread, attributes, variadics Cc:

Description

In terms of applying thread attributes right now the documentation describes only this signature:

template<typename Callable> thread(attributes& attrs, Callable func);

but this does not work when variadics are not supported (leading to error: type 'boost::thread_attributes' does not provide a call operator)

Nevertheless, this temporaray way works out:

thread(attributes& attrs, boost::bind(Callable func));

Change History (3)

comment:1 by viboes, 7 years ago

Component: threadsthread
Owner: changed from Anthony Williams to viboes
Status: newassigned

Please, don't use the threads component but the thread one.

Last edited 7 years ago by viboes (previous) (diff)

comment:2 by viboes, 7 years ago

Please, could you give an example and the compiler error you are getting.

I see on the develop branch this overload that should avoid the issue

        template <class F,class A1>
        thread(F f,A1 a1,typename disable_if<boost::thread_detail::is_convertible<F&,thread_attributes >, dummy* >::type=0):
            thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1)))
        {
            start_thread();
        }

comment:3 by jazzalex <alexander.carot@…>, 6 years ago

Sure: If I do this:

boost::thread::attributes attrs;

#if defined(BOOST_THREAD_PLATFORM_WIN32)

bool res;

res = SetThreadPriority(attrs.native_handle(),THREAD_PRIORITY_TIME_CRITICAL);

#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)

pthread_attr_setschedpolicy(attrs.native_handle(), SCHED_FIFO);

#endif

sendThread = boost::thread(attrs,&sender::sendItThreadFunction,this);

I get the following compiler error(s):

In file included from ./include/boost_1_61_0/boost/bind.hpp:22: ./include/boost_1_61_0/boost/bind/bind.hpp:319:9: error: type 'boost::thread_attributes' does not provide a call operator

unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]); ~

./include/boost_1_61_0/boost/bind/bind.hpp:1222:16: note: in instantiation of function template specialization 'boost::_bi::list2<boost::_bi::value<void

(sender::*)()>, boost::_bi::value<sender *> >::operator()<boost::thread_attributes, boost::_bi::list0>' requested here

return l_( type<result_type>(), f_, a, 0 );

./include/boost_1_61_0/boost/thread/detail/thread.hpp:116:17: note: in instantiation of member function 'boost::_bi::bind_t<void, boost::thread_attributes,

boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > >::operator()' requested here

f();

./include/boost_1_61_0/boost/thread/detail/thread.hpp:96:15: note: in instantiation of member function 'boost::detail::thread_data<boost::_bi::bind_t<void,

boost::thread_attributes, boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > > >::run' requested here

thread_data(BOOST_THREAD_RV_REF(F) f_):

./include/boost_1_61_0/boost/thread/pthread/thread_heap_alloc.hpp:24:24: note: in instantiation of member function

'boost::detail::thread_data<boost::_bi::bind_t<void, boost::thread_attributes, boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > > >::thread_data' requested here

return new T(static_cast<A1&&>(a1));

./include/boost_1_61_0/boost/thread/detail/thread.hpp:211:52: note: in instantiation of function template specialization

'boost::detail::heap_new<boost::detail::thread_data<boost::_bi::bind_t<void, boost::thread_attributes, boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > > >, boost::_bi::bind_t<void, boost::thread_attributes, boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > > >' requested here

return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(

./include/boost_1_61_0/boost/thread/detail/thread.hpp:397:25: note: in instantiation of function template specialization

'boost::thread::make_thread_info<boost::_bi::bind_t<void, boost::thread_attributes, boost::_bi::list2<boost::_bi::value<void (sender::*)()>, boost::_bi::value<sender *> > > >' requested here

thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2)))

sender.cpp:95:18: note: in instantiation of function template specialization

'boost::thread::thread<boost::thread_attributes, void (sender::*)(), sender *>' requested here

sendThread = boost::thread(attrs,&sender::sendItThreadFunction,this);

However, when I use this instead:

sendThread = boost::thread(attrs, boost::bind(&sender::sendItThreadFunction,this));

it is working perfectly fine.

Does this help to track down the issue ?

Thanks in advance and sorry again for the late reply

Alex

Note: See TracTickets for help on using tickets.