make thread work when system is not busy
Christos Gourdoupis
nospam at thank.yu
Sun Sep 2 10:50:45 PDT 2007
On Sat, 23 Dec 2006 21:11:19 +0100, vadim at wxwindows.org (Vadim Zeitlin) wrote:
>On Fri, 22 Dec 2006 14:33:44 +0100 Marco Gubernati <marco.gubernati at erxa.it> wrote:
>
>MG> wxWidgets Linux implementation for threads is of the kind "a thread per
>MG> process".
>
> wxWidgets uses pthreads API which can be implemented in any way by the
>system pthreads library, so the above statement is quite misleading.
>
>MG> The problem is, at least under wxGtk-2.6.3 (which I thorougly
>MG> inspected), is that the setpriority is called inside the
>MG> wxThread::SetPriority, which means that it will change the "priority"
>MG> (in the sense explained above) of the calling thread!! This is wrong.
>
> I don't quite understand why is it wrong for SetPriority() method to
>change the priority of the thread, could you please explain what exactly is
>bad about it?
>
> Thanks,
>VZ
I came across the same problem 8 months after the original poster reported it.
The wrong thing is that, according to the manual, wxThread::SetPriority() "can
only be set after calling Create() but before calling Run()" which implies that
it should be called from the parent process.
Thus it sets the priority of the parent process!
Furthermore, if it's called from within the child process we come across another
bug: Whatever value is given as the new priority, it always sets it to nice 19.
I suspect the problem is in threadpsx.cpp in the following line:
if ( setpriority(PRIO_PROCESS, 0, -(2*prio)/5 + 20) == -1 )
Perhaps it has something to do with "prio" being "unsigned int"?
I include the disassembly of the code that gcc produces for the above line:
wxThread::SetPriority(unsigned int)+146
0x0000000000702366 mov 0xffffffffffffffd4(%rbp),%eax
0x0000000000702369 add %eax,%eax
0x000000000070236b mov %eax,%edx
0x000000000070236d neg %edx
0x000000000070236f movl $0xcccccccd,0xffffffffffffffbc(%rbp)
0x0000000000702376 mov 0xffffffffffffffbc(%rbp),%eax
0x0000000000702379 mul %edx
0x000000000070237b mov %edx,%eax
0x000000000070237d shr $0x2,%eax
0x0000000000702380 add $0x14,%eax
0x0000000000702383 mov %eax,%edx
0x0000000000702385 mov $0x0,%esi
0x000000000070238a mov $0x0,%edi
0x000000000070238f callq 0x418bc8 <setpriority at plt>
wxGTK 2.8.4, Linux x86_64
More information about the wx-users
mailing list