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)

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

Download all attachments as: .zip

Change History (13)

comment:1 by Alvaro, 14 years ago

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

by viboes, 13 years ago

Attachment: test_ticket_2741.cpp added

by viboes, 13 years ago

Attachment: 2741_b.patch added

patch src

by viboes, 13 years ago

Attachment: 2741_a.patch added

patch headers

comment:2 by viboes, 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 tim@…, 11 years ago

Cc: tim@… added

comment:4 by viboes, 11 years ago

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

comment:5 by viboes, 11 years ago

Cc: viboes added
Milestone: Boost 1.39.0To Be Determined

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

comment:6 by viboes, 11 years ago

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

comment:7 by viboes, 11 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:8 by viboes, 11 years ago

Milestone: To Be DeterminedBoost 1.49.0

comment:9 by viboes, 11 years ago

Committed in trunk at revision [76543].

comment:10 by viboes, 10 years ago

Milestone: Boost 1.49.0Boost 1.50.0
Resolution: fixed
Status: assignedclosed

Committed in release branch at [78543]

Note: See TracTickets for help on using tickets.