PDA

View Full Version : Thread object methods



Mark F
March 7th, 2005, 09:57 AM
I've been trying to use the thread object methods :getthreadpriority() and :setthreadpriority() described in the latest G4A8MT2 distribution help file. I'm not having any luck with either one.

:getthreadpriority() doesn't appear to return anything (nil)
:getthreadpriority() appears to require an undocumented input value (number)
:setthreadpriority() doesn't appear to change the priority (checked in a debugger)
:setthreadpriority() doesn't appear to return the previous priority

Before you ask, the spawned thread is NOT exiting before the calls are made. :)

Here is code that shows most of these problems:


local function printandwait(num)

for i=1, num do
print("help "..i)
win.Sleep(1000)
end

end

local to = thread.newthread(printandwait,{5})
print(to:getthreadpriority(1))
print(to:setthreadpriority(thread.THREAD_PRIORITY_ ABOVE_NORMAL))
print(to:getthreadpriority(1))


The output looks like this:


help 1
nil
nil
nil
help 2
help 3
help 4
help 5


Am I using these wrong?

birty
March 7th, 2005, 10:59 AM
i assume these are the same as the windows thread functions, if so you need to pass a handle to the thread in question or it wont do anything. see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/process_and_thread_functions.asp for a list of all the functions, to set the priority of the current thread you would need to call

setthreadpriority(getcurrentthread(),priority)

Mark F
March 7th, 2005, 11:38 AM
But these are methods on a LUA userdata object. According to the help file, they are invoked using ":", not ".". This means they get a reference to self as the first parameter. I assume the userdata object contains the thread handle which means there should be no reason to pass the handle to the method.

However, I have never seen the implementation of these functions so I could be very wrong. :D

Promixis
March 7th, 2005, 12:35 PM
will ask Ron :D, I was just about to start playing with those functions..

Ron
March 7th, 2005, 02:58 PM
Fixed both problems. Thanks for reporting them.

Mark F
March 7th, 2005, 03:50 PM
Thanks. Much better. :)

Ron
March 7th, 2005, 03:52 PM
No problem.