Extending the boost::thread class
Hi all, I want to use the boost thread library as a base for my multiplatform thread class. After I have studied the documentation I recognize that there are not all things available at the moment what I need, so I try to find out what is the best way to start my implementation. What I need, is to implement the following additional methods: suspend, resume, stop (or terminate), set_priority, get_priority, get_state and I want to have the possibility to create threads in a suspend mode. I want to use the boost thread as is and extend the needed features in my own class, but it seems so that their is at the moment no legal way to get the internal thread resource from a created thread, so that I can implement the missing and perhaps not portable features by my own? So what is the prefered way to extend the thread class? Is their a reasonable way to do it or should I build my own class from scratch? many thanks for any input and guess, regards Arno
arno.schaefer@sqs.de wrote:
Hi all, I want to use the boost thread library as a base for my multiplatform thread class. After I have studied the documentation I recognize that there are not all things available at the moment what I need, so I try to find out what is the best way to start my implementation. What I need, is to implement the following additional methods: suspend, resume, stop (or terminate), set_priority, get_priority, get_state and I want to have the possibility to create threads in a suspend mode. <snip>
Why do you think you want suspend, resume and terminate? There are very few safe uses for these operations, and programs that use them tend to suffer from data corruption and/or deadlocks. It would be fairly easy to add support for priority settings to Boost.Thread, but since priority values are only meaningful in the context of a scheduling policy and policies vary between operating systems it would be hard to provide a genuinely portable priority system.
"Ben Hutchings"
arno.schaefer@sqs.de wrote:
Hi all, I want to use the boost thread library as a base for my multiplatform thread class. After I have studied the documentation I recognize that there are not all things available at the moment what I need, so I try to find out what is the best way to start my implementation. What I need, is to implement the following additional methods: suspend, resume, stop (or terminate), set_priority, get_priority, get_state and I want to have the possibility to create threads in a suspend mode. <snip>
Why do you think you want suspend, resume and terminate? There are very few safe uses for these operations, and programs that use them tend to suffer from data corruption and/or deadlocks.
It would be fairly easy to add support for priority settings to Boost.Thread, but since priority values are only meaningful in the context of a scheduling policy and policies vary between operating systems it would be hard to provide a genuinely portable priority system.
For what it's worth, William Kempf began an implementation of thread priorities and an exception-based thread cancellation scheme on the thread_dev branch before he stopped working on Boost.Threads. If it's completed enough (I haven't examined it closely enough yet to tell), I hope to move it into the a Boost release after the upcoming 1.32. That won't help you right now, however. Mike
participants (3)
-
arno.schaefer@sqs.de
-
Ben Hutchings
-
Michael Glassford