Modify

Ticket #2741 (closed Feature Requests: fixed)

Opened 5 years ago

Last modified 23 months ago

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

test_ticket_2741.cpp Download (2.1 KB) - added by viboes 5 years ago.
2741_b.patch Download (757 bytes) - added by viboes 5 years ago.
patch src
2741_a.patch Download (8.2 KB) - added by viboes 5 years ago.
patch headers

Change History

comment:1 Changed 5 years ago by Alvaro

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

Changed 5 years ago by viboes

Changed 5 years ago by viboes

patch src

Changed 5 years ago by viboes

patch headers

comment:2 Changed 5 years ago by viboes

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 Changed 2 years ago by tim@…

  • Cc tim@… added

comment:4 Changed 2 years ago by viboes

See also #5956 Add optional stack_size argument to thread::start_thread()

comment:5 Changed 2 years ago by viboes

  • Cc viboes added
  • Milestone changed from Boost 1.39.0 to To Be Determined

See also #2880 Request for Thread scheduler support for boost ..

comment:6 Changed 2 years ago by viboes

See also #3696 Boost Thread library lacks any way to set priority of threads

comment:7 Changed 2 years ago by viboes

  • Owner changed from anthonyw to viboes
  • Status changed from new to assigned

comment:8 Changed 2 years ago by viboes

  • Milestone changed from To Be Determined to Boost 1.49.0

comment:9 Changed 2 years ago by viboes

Committed in trunk at revision [76543].

comment:10 Changed 23 months ago by viboes

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone changed from Boost 1.49.0 to Boost 1.50.0

Committed in release branch at [78543]

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.