Subject: [Boost-bugs] [Boost C++ Libraries] #2741: proposal to manage portable and non portablethread attributes
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-02-10 16:43:46
#2741: proposal to manage portable and non portablethread attributes
-------------------------------+--------------------------------------------
Reporter: viboes | Owner: anthonyw
Type: Feature Requests | Status: new
Milestone: Boost 1.39.0 | Component: thread
Version: Boost 1.37.0 | Severity: Not Applicable
Keywords: thread attributes |
-------------------------------+--------------------------------------------
Boost.thread has already a non portable interface to get the thread handle
{{{
#!cpp
class thread {
public:
...
typedef np_native_handle_type native_handle_type;
native_handle_type native_handle();
...
};
}}}
Boost.Thread do not allows to pass thread attributes on the thread
constructor. I suppose that this is due to portable issues. Could we
identify which attributes are portable and which one not?
The portable attributes (as stack size, ...) can be grouped on a
thread_attributes class.
In order to be able to pass whatever attribute to the thread constructor
we
can add the setting of non portable attributes to this thread_attributes
class, and making the thread constructor take a thread_attributes in
addition to the existing parameters.
{{{
#!cpp
class thread {
public:
class thread_attributes {
// portable attributes
public:
typedef np_native_handle_type native_handle_type;
native_handle_type native_handle();
// set/get of attributes
// ..
#if defined(BOOST_THREAD_PLATFORM_WIN32)
// ... window version
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
private:
pthread_attr_t native_attributes;
public:
thread_attributes() {
pthread_attr_init(&native_attributes);
}
~thread_attributes() {
pthread_attr_destroy(&native_attributes);
}
// ... other
#else
#error "Boost threads unavailable on this platform"
#endif
};
thread(const thread_attributes&p, F f,A1 a1);
...
};
}}}
The portable application needing some specific configuration can construct
portable threads using the following schema
{{{
#!cpp
thread::thread_attributes attr;
// set portable attributes
// ...
attr.set_stack_size(1000000)
#if defined(BOOST_THREAD_PLATFORM_WIN32)
// ... window version
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
// ... pthread version
pthread_attr_setschedpolicy(attr.get_native_handle(), SCHED_RR);
#else
#error "Boost threads unavailable on this platform"
#endif
thread th(attr, f,ctx);
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2741> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC