# Thread#priority(=) will be obsolete

**URL:** <https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634>\
**Category:** Development\
**Created:** [August 12, 2008, 11:10am UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634 "2008-08-12T11:10:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SASADA\_Koichi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@SASADA\_Koichi](https://www.ruby-forum.com/u/SASADA_Koichi)\
**Post date:** [August 12, 2008, 11:10am UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634/1 "2008-08-12T11:10:46Z")

</div>

Hi,

We are planning to make Thread#priority(=) method as obsolete method  
from Ruby 1.9.x. This is due to implimentation/practical (maybe no  
one use it) reason.

Any comments?

---

<div class="post-metadata">

**Author:** ![SASADA\_Koichi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@SASADA\_Koichi](https://www.ruby-forum.com/u/SASADA_Koichi)\
**Post date:** [August 12, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634/2 "2008-08-12T20:04:07Z")

</div>

On Tue, 2008-08-12 at 18:06 +0900, SASADA Koichi wrote:

> We are planning to make Thread#priority(=) method as obsolete method  
> from Ruby 1.9.x. This is due to implimentation/practical (maybe no  
> one use it) reason.

> Any comments?

Some way to reduce thread priority is important for situations like  
idling work-stealing threads in a nonblocking/lockfree way, which is a  
situation I’ve come up against recently.

-mental

---

<div class="post-metadata">

**Author:** ![SASADA\_Koichi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@SASADA\_Koichi](https://www.ruby-forum.com/u/SASADA_Koichi)\
**Post date:** [August 13, 2008, 4:30am UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634/3 "2008-08-13T04:30:49Z")

</div>

Hi,

MenTaLguY wrote:

> Some way to reduce thread priority is important for situations like  
> idling work-stealing threads in a nonblocking/lockfree way, which is a  
> situation I’ve come up against recently.

inserting sleep is not enough?

---

<div class="post-metadata">

**Author:** ![SASADA\_Koichi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@SASADA\_Koichi](https://www.ruby-forum.com/u/SASADA_Koichi)\
**Post date:** [August 13, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634/4 "2008-08-13T23:00:29Z")

</div>

From: “SASADA Koichi” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> (optional-3: we should choose 1 or 2 on build/launch timing)  
> Interesting. This is what we’ve been doing on Unix systems  
> having pthreads. However, I’ve not actually empirically  
> verified it had any effect:

void set\_thread\_priority\_low ()  
{  
struct sched\_param sp;  
int policy;

```
memset(&sp, 0, sizeof(struct sched_param));
pthread_getschedparam(pthread_self(), &policy, &sp);
sp.sched_priority = sched_get_priority_min(policy);
(void) pthread_setschedparam(pthread_self(), policy, &sp);

```

}

So when you say, “not affect on most UNIX environment” it makes  
me wonder: does the above really work, or not? 🙂

For completeness’ sake, here’s what we’re doing on Windows:

void set\_thread\_priority\_low ()  
{  
SetThreadPriority(GetCurrentThread(), THREAD\_PRIORITY\_BELOW\_NORMAL);  
}

Personally I think it would be nice if ruby retained the  
ability to say “make this thread low priority”, even if  
the non-portable integer priority values are removed.

(However, if that pthread code really has no effect on  
most Unix systems, then . . . . I dunno 🙂

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![SASADA\_Koichi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@SASADA\_Koichi](https://www.ruby-forum.com/u/SASADA_Koichi)\
**Post date:** [September 8, 2008, 9:39am UTC](https://www.ruby-forum.com/t/thread-priority-will-be-obsolete/145634/5 "2008-09-08T09:39:39Z")

</div>

On Wed, Aug 13, 2008 at 11:27:14AM +0900, SASADA Koichi wrote:

> Hi,
> 
> MenTaLguY wrote:
> 
> > Some way to reduce thread priority is important for situations like  
> > idling work-stealing threads in a nonblocking/lockfree way, which is a  
> > situation I’ve come up against recently.
> 
> inserting sleep is not enough?  
> No. In my application (a robot control framework), I have a control  
> thread a  
> multiple planning threads. The control thread _MUST_ be prioritized vs.  
> the  
> planning thread, otherwise reaction to problems could be delayed because  
> of high  
> planning load – leading to a robot physical crash for instance 😉

Thread priorities are useful. Please do not remove them (and sleeping is  
really  
a hack in case MenTaLguY described), given that in worst cases one would  
do  
nothing while CPU is available).

Sylvain
