Opened 14 years ago
Closed 10 years ago
#2741 closed Feature Requests (fixed)
proposal to manage portable and non portablethread attributes
Reported by: | viboes | Owned by: | viboes |
---|---|---|---|
Milestone: | Boost 1.50.0 | Component: | thread |
Version: | Boost 1.37.0 | Severity: | Not Applicable |
Keywords: | thread attributes | Cc: | tim@…, viboes |
Description
Boost.thread has already a non portable interface to get the thread handle
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.
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
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);
Attachments (3)
Change History (13)
by , 13 years ago
Attachment: | test_ticket_2741.cpp added |
---|
comment:2 by , 13 years ago
The attached files contains the test of the new feature and a two patch implementing it: one for the headers and one for the sources.
comment:3 by , 11 years ago
Cc: | added |
---|
comment:4 by , 11 years ago
See also #5956 Add optional stack_size argument to thread::start_thread()
comment:5 by , 11 years ago
Cc: | added |
---|---|
Milestone: | Boost 1.39.0 → To Be Determined |
See also #2880 Request for Thread scheduler support for boost ..
comment:6 by , 11 years ago
See also #3696 Boost Thread library lacks any way to set priority of threads
comment:7 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 11 years ago
Milestone: | To Be Determined → Boost 1.49.0 |
---|
comment:10 by , 10 years ago
Milestone: | Boost 1.49.0 → Boost 1.50.0 |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Committed in release branch at [78543]