Author Topic: Need guide with threads...  (Read 1365 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Need guide with threads...
« on: May 07, 2019, 03:38:29 PM »
 I apologize, i promise i have tried to make it work, but it siply wont work.

 I have this code in PowerBASIC:

Code: [Select]
FUNCTION ThreadFunc(BYVAL x AS LONG) AS LONG
SLEEP 3000
END FUNCTION

FUNCTION PBMAIN () AS LONG

 LOCAL hThread AS DWORD
 LOCAL ThreadValue AS LONG
 LOCAL idthread AS LONG
 LOCAL retval AS LONG

 ThreadValue = 17

 hThread = CreateThread(BYVAL %Null, 0, CODEPTR(ThreadFunc),   ThreadValue, _
                      %THREAD_TERMINATE OR %THREAD_QUERY_INFORMATION, _
                      BYVAL VARPTR(idThread))

 IF hThread <> %INVALID_HANDLE_VALUE THEN
     GetExitCodeThread(hThread, Retval)
     MSGBOX IIF$(retval=259, "YES, IT WORKS", "NO, IT DOESNT WORK!")
     CloseHandle hThread
 END IF

END FUNCTION

 I have coded it several ways and it always displays "NO, IT DOESNT WORK!"

Apparently the thread is not created with %THREAD_QUERY_INFORMATION, but i dont want to mess with custom security descriptors in Oxygen yet.

Added:
 The above code works on PowerBASIC, but on Oxygen GetExitCodeThread() always returns false, and sets the last error to 6: "Invalid handle", or returns false with no errors. According to the docs, it is because it doesnt have the THREAD_QUERY_INFORMATION, but this method does not work and i am not fluent enough on Oxygen to create a security descriptor manually, and even if i do, i do not know if i am doing it correctly. I am also guessing it could be because CreateThread() is inherithing the security descriptor from the executable, but oxygen's executables are created without this security descriptor... maybe?

 Can i get some help converting it? Im trying to get the thread status to see if it has finished or not.
« Last Edit: May 07, 2019, 04:38:12 PM by Brian Alvarez »

Brian Alvarez

  • Guest
Re: Need guide with threads...
« Reply #1 on: May 07, 2019, 04:51:59 PM »
 I just noticed something weird; while evaluating the results, this:

Code: [Select]
print "ERROR: " + th + ":" + GetLastError() + "<" + R +">"
Outputs this:

Code: [Select]
ERROR: 124:0<0>
While this:

Code: [Select]
print "ERROR: " + GetLastError() + ":" + R +":"
Outputs this:

Code: [Select]
ERROR: 6:0:
 I must re-evaluate my results...

Brian Alvarez

  • Guest
Re: Need guide with threads...
« Reply #2 on: May 07, 2019, 04:59:25 PM »
It seems like debugging with "print" was misleading me. It all works now.  :o