Is this a TThread bug on Android?

in windows, we can call MyThread.waitfor several times in the same thread. if the thread has already completed without problems, it will not raise any exceptions and will immediately return (normal behavior).

on Android, it's different if we call MyThread.waitfor twice, then we will have an exception in the second attempt with "There is no such process."

function TThread.WaitFor: LongWord;
{$ELSEIF Defined(POSIX)}
var
  X: Pointer;
  ID: pthread_t;
begin
  if FExternalThread then
    raise EThread.CreateRes(@SThreadExternalWait);
  ID := pthread_t(FThreadID);
  if CurrentThread.ThreadID = MainThreadID then
    while not FFinished do
      CheckSynchronize(1000);
  FThreadID := 0;
  X := @Result;
  CheckThreadError(pthread_join(ID, X));
end;
{$ENDIF POSIX}

the error occurs because when they call waitfor they set FThreadID: = 0, so any further call will be stopped

I think it should be written like this:

function TThread.WaitFor: LongWord;
{$ELSEIF Defined(POSIX)}
begin
  if FThreadID = 0 then exit;
  ...
end;
{$ENDIF POSIX}

What do you think? did I need to open a request for input error?

+4
source share
1 answer

pthread_join :

, , undefined.

, TThread , undefined.

? . , , . Windows . pthreads. :

, undefined.

, Embarcadero Posix, Windows. , , . , , WaitFor . , . , ?

, FThreadID 0, undefined . , WaitFor, , undefined .

,

, , WaitFor pthread_join, . Embarcadero TThread , , . Windows , pthreads.

Embarcadero , , Posix . Windows , - pthread_join.

, , pthreads. pthreads . , . , , .

, , , , Embarcadero, . , . . , - , , , . , , , , Delphi TThread.WaitFor .

+5

Source: https://habr.com/ru/post/1661118/


All Articles