Forwarding a message from Jonas Mabe to the MacPascal mailing list:
Peter N Lewis wrote:
To properly handle MP threading, the RTS would, at the least, require everything to have a returned error result, rather than using IOResult, which would be a big change (although this would be desirable for New as well).
FWIW, in Free Pascal we solved this problem with the introduction of the "threadvar" keyword (which may have been copied from Delphi, I don't know). A threadvar consists of two parts:
a) first an index into some structure which contains the value of this variable in case of a multi-threaded program b) next room to contain the value of this variable in case of a single-threaded program.
E.g. the assignment in this program:
threadvar a: longint;
begin a := 5; end.
is compiled into this:
# [5] a := 5; lis r2,ha16(FPC_THREADVAR_RELOCATE) lwz r2,lo16(FPC_THREADVAR_RELOCATE)(r2) cmplwi cr0,r2,0 beq cr0,L5 lis r4,ha16(U_P$PROGRAM_A) lwz r3,lo16(U_P$PROGRAM_A)(r4) mtctr r2 bctrl b L6 L5: lis r3,ha16(U_P$PROGRAM_A+4) addi r3,r3,lo16(U_P$PROGRAM_A+4) L6: li r2,5 stw r2,0(r3)
Of course, such a solution for ioresult is slower than returning an error from a function, but on the other hand it is fully compatible with existing code (also in the RTL/RTS, except if such variables are somewhere used in assembler code).
Jonas