Unit 'exec' Package
[Overview][Constants][Types][Procedures and functions][Variables][Index] [#morphunits]

TLSCallDestructors

Call Thread-Local Storage index destructors for the given task (V51.46)

Declaration

Source position: exec.pas line 2349

procedure TLSCallDestructors(

  Task: PTask

);

Description

Calls destructors for all Thread-Local Storage indices with non-NULL value. The value is passed to the destructor as the first parameter. The value for the given index is set to nil before the call.

If new indices with destructors appear after the destructors have been called this function performs unspecified number of retries until either there are no more destructors to call or the function gives up due to excessive retry attempts.

Attention

TLSCallDestructors is mainly meant to be used by someone implementing a custom threading solution. This function can be called after the thread has completed its processing and is about the end.

Calling this function for any other purpose, or before being terminated is illegal.

Calling this function for other task than self is unwise. The destructor functions might not be called in this case, but could still get deallocated and not called again, ever. Just Don't Do It.

Errors

MorphOS 3.14 (exec 51.46) had a bug which resulted in the destructors being called out of the expected order. In particular this could cause issues if destructor execution expected destructors getting called once before (potentially) getting called again. This bug was fixed in MorphOS 3.15 (exec 51.48) and later versions. Now all destructors are guaranteed to get called once before getting called again due to non-nil value appearing during some destructor function execution.

See also

TLSFree

  

Free Thread-Local Storage index

TLSAlloc

  

VarArgs version of TLSAllocA

TLSSetValue

  

set the task specific value associated with a given Thread-Local Storage index (V51.46)

TLSGetValue

  

get the task specific value associated with a given Thread-Local Storage index (V51.46)

Example

procedure Proc(Parent: PTask; ParentSigMask: LongWord);
begin
  // Much work here...

  // Call destructors before we do internal cleanup
  TLSCallDestructors(nil);
  // Some cleanup that we need to do before exit
      

  Forbid();
  Signal(Parent, ParentSigMask);
end;

var
  Sig: ShortInt;
begin
  Sig := AllocSignal(-1);
  if Sig <> -1 then
  begin
    if CreateNewProc([
      NP_Entry,    AsTag(@Proc),
      NP_CodeType, CODETYPE_PPC,
      NP_PPC_Arg1, AsTag(FindTask(nil)),
      NP_PPC_Arg2, 1 shl Sig,
      TAG_DONE]) <> 0 then
    begin
      Wait(1 shl Sig);
    end;
  FreeSignal(Sig);
end;

Documentation generated on: 2021-07-30