Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Division by 0 in Thread::Priority
Division by 0 in Thread::Priority [message #45011] Mon, 17 August 2015 08:16 Go to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
If Priority function is executed with priority level above 125 (for example 150) there is division by 0.

bool Thread::Priority(int percent)
{

[...]

	if (pthread_setschedparam(handle, policy, &param)) {// if this function fails (user has no right to set such high priority)
		policy = SCHED_OTHER;
		//max is changed from 175 to 125
		percent_max = 125;
		//min is still 125
		percent_min = minmax(percent_min, 0, percent_max);
		//and (percent_max - percent_min) is 0
		param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))*(minmax(percent, percent_min, percent_max)-percent_min)/(percent_max - percent_min);

Re: Division by 0 in Thread::Priority [message #45019 is a reply to message #45011] Wed, 19 August 2015 09:33 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
For now, quick fix:

		param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))
		                       * (minmax(percent, percent_min, percent_max) - percent_min)
		                       / max(percent_max - percent_min, 1);
Previous Topic: [solved] Bug in SSL or it's me ?
Next Topic: [GCC][C++11] error: call of overloaded 'pick(Upp::Any&)' is ambiguous
Goto Forum:
  


Current Time: Thu Mar 28 11:42:44 CET 2024

Total time taken to generate the page: 0.01152 seconds