impossible bug under ARM lazarus / 62-General ---------------------------------------------------------------------- TCH · 2018-08-28 21:43 I'm currently facing something unreal. The problem is, that some part of the code does not triggered, when it needed, but when i put logging lines there (no other changes!), then it works, so i cannot debug it, what it is the problem. The only difference was, once i managed to debug out that one of the variables was 0, instead of 500, but that variable was set constantly in the beginning and nowhere else it was touched in the code. What can cause this? I turned off optimization and smartlinking. The program has two other threads, but until this point in development nothing was wrong. (At least no such bugs.) It's FreePascal 3.0.2 under Armbian and Orange Pi. ---------------------------------------------------------------------- Thaddy · 2018-08-29 04:39 without code this is hard to tell. Does the compiler give any feedback like "variable x is declared but never used."? Try to compile with -Sew, solve everything where it stops and give us all that the compiler spits out, should be just hints. (Don't be pedantic, solve everything. Compiler knows best. Only idiots ignore warnings) Do you check function results? Does the variable rely on OS functions that you call as procedure? (I saw once you tend to NOT check OS calls, like fpOpen etc, hence this remark) Is the variable accessed from one of the threads? Because I had something similar (my mistake!) that could be solved by simply accessing the variable once explicitly from the thread in which it was declared. Put {$optimizations off} on top of the unit where the variable is declared, just to be sure. But without code that reproduces the problem this remains guessing. Start by at least showing us the compiler output and start with fixing all warnings and check all OS calls for validity. ---------------------------------------------------------------------- TCH · 2018-08-29 08:12 No, the compiler gives no warnings. The linker gives the usual warning: "link.res contains output sections; did you forget -T?" I compiled it with the sole parameter -Sew, here is the output:Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Free Pascal Compiler version 3.0.2 [2017/02/17] for armCopyright (c) 1993-2017 by Florian Klaempfl and othersTarget OS: Linux for ARMHFCompiling xc0x.pasCompiling ./pascal_units/tcpipserver.pasCompiling config.pasCompiling ./pascal_units/elif_parser.pasCompiling ./pascal_units/strarrfunc.pasAssembling strarrfuncAssembling elif_parserCompiling ./pascal_units/log.pasAssembling logCompiling ./pascal_units/rcmkdir.pasAssembling rcmkdirAssembling configAssembling tcpipserverCompiling ./pascal_units/sockerrmsg.pasAssembling sockerrmsgCompiling ./pascal_units/usbkeyb.pasAssembling usbkeybCompiling ./pascal_units/serialport.pasAssembling serialportCompiling ./pascal_units/signalhandler.pasAssembling signalhandlerCompiling ./pascal_units/daemon.pasAssembling daemonCompiling ./pascal_units/tstamp64.pasAssembling tstamp64Compiling ./pascal_units/sfutils.pasAssembling sfutilsCompiling ./pascal_units/pinmatrix.pasCompiling ./pascal_units/el_gpio.pasAssembling el_gpioAssembling pinmatrixCompiling ac01_protocol.pasCompiling ./pascal_units/shexec.pasAssembling shexecCompiling web.pasAssembling webAssembling ac01_protocolAssembling xc0xLinking xc0x/usr/bin/ld: warning: link.res contains output sections; did you forget -T? I do check function results, unless their result is irrelevant. What you saw in my GPIO unit was the result of a quickly thrown together unit where i forgot to check the result of memory mappings. I already fixed that. In the meantime i found where the variable is overwritten, in the TCP/IP server unit at the fpSelect. The weird thing is that variable is in the main thread and aside the initializing and config reloading, nothing ever touch it. I cannot share all code, because it is a company project, but the TCP/IP server unit is a generic stuff, not a secret one, so here it's code (the relevant line marked, but still i fear, that the bug is not there), but this was my first network code ever, so don't be surprised, if something is solved not properly inside:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit TCPIPServer; {$optimization off} {$mode objfpc}{$H+} interface uses classes, sockets, baseunix; const        FUNC_CODE_SOCKET   = 1;      FUNC_CODE_BIND     = 2;        FUNC_CODE_LISTEN   = 3;        FUNC_CODE_ACCEPT   = 4;        FUNC_CODE_RECV     = 5;        FUNC_CODE_SEND     = 6; type        callback_procedure = procedure(c: pointer);         TTCPIPServerCommArgs = record                socket_to_listen: longint;                client_index: longint;              bufsize: longword;                client_received_callback: callback_procedure;                client_error_callback: callback_procedure;                client_closed_callback: callback_procedure;                client_sent_callback: callback_procedure;        end;        PTCPIPServerCommArgs = ^TTCPIPServerCommArgs;         TTCPIPServerArgs = record              port: word;                backlog: byte;                bufsize: longword;                client_created_callback: callback_procedure;                client_received_callback: callback_procedure;              client_error_callback: callback_procedure;                client_closed_callback: callback_procedure;                client_sent_callback: callback_procedure;        end;        PTCPIPServerArgs = ^TTCPIPServerArgs;         TTCPIPServerCommThread = class(TThread)                private                protected                      ts0, ts1: timespec;                        ListenSocket: longint;                        ClientAddr: TInetSockAddr;                        ClientAddrSize: LongInt;                      ClientSocket: Longint;                        c_client_index: longint;                        outBuf: pbyte;                      outBufSize: longword;                        Buffer: pbyte;                        c_BufferContentSize: longword;                      CLIENT_BUFFER_SIZE: longword;                        ERROR_FUNC_CODE, SOCKET_ERROR_CODE: longint;                        FDS: TFDSet;                        c_client_received_callback: callback_procedure;                        c_client_error_callback: callback_procedure;                        c_client_closed_callback: callback_procedure;                        c_client_sent_callback: callback_procedure;                        procedure Execute; override;                public                        Constructor Create(args: PTCPIPServerCommArgs);                        function ClientIndex: LongInt;                        procedure GetLastError(func_error: plongint; socket_error: plongint);                      procedure FreeBuffer;                        procedure RecvAck;                        function BufferContentSize: longword;                        function BufferPointer: pbyte;                      procedure Send(buf: pbyte; size: longword);                      function OutBufferEmpty: boolean;                        procedure FinishClient(HaltTime: longword);        end;        PTCPIPServerCommThread = ^TTCPIPServerCommThread;         TTCPIPServerThread = class(TThread)                private              protected                        ts0, ts1: timespec;                      srv_port: word;                        srv_backlog: byte;                      ListenSocket: longint;                        ServerAddr: TInetSockAddr;                        clients: array of TTCPIPServerCommThread;                        client_count: longint;                        thrargs: TTCPIPServerCommArgs;                      FDS: TFDSet;                        ERROR_FUNC_CODE, SOCKET_ERROR_CODE: longint;                        CLIENT_BUFFER_SIZE: longword;                        last_client: longint;                      srv_client_created_callback: callback_procedure;                      srv_client_received_callback: callback_procedure;                      srv_client_error_callback: callback_procedure;                      srv_client_closed_callback: callback_procedure;                      srv_client_sent_callback: callback_procedure;                      procedure Execute; override;                public                      Constructor Create(args: PTCPIPServerArgs);                      procedure GetLastError(func_error: plongint; socket_error: plongint);                        procedure GetClientLastError(index: longint; func_error: plongint; socket_error: plongint);                      function ClientCount: longint;                        function LastCreatedClient: longint;                        procedure RecvAck(index: longint);                        function BufferContentSize(index: longint): longword;                        function BufferPointer(index: longint): pbyte;                        procedure Send(index: longint; buf: pbyte; size: longword);                      function OutBufferEmpty(index: longint): boolean;                      procedure FinishServer(HaltTime: longword);        end; implementation constructor TTCPIPServerCommThread.Create(args: PTCPIPServerCommArgs);begin        inherited Create(false);        FreeOnTerminate := False;        Self.Priority := tpLowest;        Self.ts0.tv_sec  := 0;        Self.ts0.tv_nsec := 50000000;        Self.ListenSocket := args^.socket_to_listen;        Self.c_client_index := args^.client_index;        Self.CLIENT_BUFFER_SIZE := args^.bufsize;        Self.c_BufferContentSize := 0;        Self.c_client_received_callback := args^.client_received_callback;        Self.c_client_error_callback := args^.client_error_callback;        Self.c_client_closed_callback := args^.client_closed_callback;        Self.c_client_sent_callback := args^.client_sent_callback;        Self.ClientAddrSize := sizeof(Self.ClientAddr);        Self.FDS := Default(TFDSet);        Self.ERROR_FUNC_CODE := 0;        Self.SOCKET_ERROR_CODE := 0;        Self.ClientSocket := fpaccept(Self.ListenSocket, @(Self.ClientAddr), @(Self.ClientAddrSize));        if (ClientSocket < 0) then        begin                Self.ERROR_FUNC_CODE := FUNC_CODE_ACCEPT;              Self.SOCKET_ERROR_CODE := SocketError;                Self.Terminate;                exit;        end;        Self.Buffer := GetMem(Self.CLIENT_BUFFER_SIZE);end; procedure TTCPIPServerCommThread.Execute;var RD_Count, WT_Count: longint;begin      while (not Self.Terminated) do        begin                if (Self.c_BufferContentSize = 0) then                begin                      fpFD_Zero(Self.FDS);                        fpFD_Set(Self.ClientSocket, Self.FDS);                        fpSelect(Self.ClientSocket + 1, @(Self.FDS), nil, nil, 5000); // HERE BE BUGS...                        if ((not Self.Terminated) and (fpFD_ISSET(Self.ClientSocket, Self.FDS) <> 0)) then                      begin                                RD_Count := fprecv(Self.ClientSocket, @(Self.Buffer[0]), Self.CLIENT_BUFFER_SIZE, 0);                                if (RD_Count < 0) then                              begin                                        Self.ERROR_FUNC_CODE := FUNC_CODE_RECV;                                      Self.SOCKET_ERROR_CODE := SocketError;                                      if (Self.c_client_error_callback <> nil) then                                      begin                                              Self.c_client_error_callback(@(Self));                                      end;                                end                              else                                begin                                      if (RD_Count > 0) then                                      begin                                              Self.c_BufferContentSize := RD_Count;                                              if (Self.c_client_received_callback <> nil) then                                              begin                                                      Self.c_client_received_callback(@(Self));                                              end;                                        end                                      else                                      begin                                                Self.Terminate;                                        end;                              end;                        end;                end;                if (Self.OutBufSize > 0) then                begin                        WT_Count := fpSend(Self.ClientSocket, Self.OutBuf, Self.OutBufSize, 0);                        if (WT_Count < 0) then                        begin                                Self.ERROR_FUNC_CODE := FUNC_CODE_SEND;                              Self.SOCKET_ERROR_CODE := SocketError;                                if (Self.c_client_error_callback <> nil) then                              begin                                        Self.c_client_error_callback(@(Self));                                end;                        end                        else                      begin                                Self.OutBufSize := Self.OutBufSize - WT_Count;                                Self.OutBuf := Self.OutBuf + WT_Count;                                if (Self.OutBufSize = 0) then                                begin                                      if (Self.c_client_sent_callback <> nil) then                                        begin                                              Self.c_client_sent_callback(@(Self));                                      end;                              end;                        end;                end;                if ((Self.c_BufferContentSize > 0) and (Self.OutBufSize = 0)) then              begin                        fpnanosleep(@(Self.ts0), @(Self.ts1));                end;        end;        CloseSocket(Self.ClientSocket);        if (Self.c_client_closed_callback <> nil) then        begin              Self.c_client_closed_callback(@(Self));        end;end; function TTCPIPServerCommThread.ClientIndex: LongInt;begin        Result := Self.c_client_index;end; procedure TTCPIPServerCommThread.GetLastError(func_error: plongint; socket_error: plongint);begin        func_error^ := Self.ERROR_FUNC_CODE;        socket_error^ := Self.SOCKET_ERROR_CODE;end; procedure TTCPIPServerCommThread.FreeBuffer;begin        FreeMem(Self.Buffer);end; procedure TTCPIPServerCommThread.RecvAck;begin        Self.c_BufferContentSize := 0;end; function TTCPIPServerCommThread.BufferContentSize: longword;begin        Result := Self.c_BufferContentSize;end; function TTCPIPServerCommThread.BufferPointer: pbyte;begin        Result := Self.Buffer;end; procedure TTCPIPServerCommThread.Send(buf: pbyte; size: longword);begin        Self.OutBuf := buf;        Self.OutBufSize := size;end; function TTCPIPServerCommThread.OutBufferEmpty: boolean;begin        Result := Self.OutBufSize = 0;end; procedure TTCPIPServerCommThread.FinishClient(HaltTime: longword);var count: longword;begin        if (Self.Finished or Self.Terminated) then      begin                exit;        end;         count := (HaltTime div 50) + 1;        Self.Terminate;        while ((not Self.Finished) and (count > 0)) do        begin                fpnanosleep(@(Self.ts0), @(Self.ts1));                dec(count);        end;        Self.FreeBuffer;end; constructor TTCPIPServerThread.Create(args: PTCPIPServerArgs);begin        inherited Create(false);        FreeOnTerminate := False;        Self.Priority := tpLowest;        Self.ts0.tv_sec  := 0;        Self.ts0.tv_nsec := 50000000;        Self.client_count := 0;        setlength(Self.clients, Self.client_count);        Self.srv_port := args^.port;        Self.srv_backlog := args^.backlog;        Self.CLIENT_BUFFER_SIZE := args^.bufsize;        Self.srv_client_created_callback := args^.client_created_callback;        Self.srv_client_received_callback := args^.client_received_callback;      Self.srv_client_error_callback := args^.client_error_callback;      Self.srv_client_closed_callback := args^.client_closed_callback;      Self.srv_client_sent_callback := args^.client_sent_callback;      Self.ServerAddr.sin_family := AF_INET;        Self.ServerAddr.sin_addr.s_addr := INADDR_ANY;        Self.ServerAddr.sin_port := htons(Self.srv_port);        Self.FDS := Default(TFDSet);        Self.ERROR_FUNC_CODE := 0;        Self.SOCKET_ERROR_CODE := 0;        Self.ListenSocket := fpSocket (AF_INET, SOCK_STREAM, 0);        if (Self.ListenSocket < 0) then      begin                Self.ERROR_FUNC_CODE := FUNC_CODE_SOCKET;              Self.SOCKET_ERROR_CODE := SocketError;                Self.Terminate;                exit;        end;        fpSetSockOpt(Self.ListenSocket, SOL_SOCKET, SO_REUSEADDR, PChar('True'), Length('True'));        if (fpBind(Self.ListenSocket, @(Self.ServerAddr), sizeof(Self.ServerAddr)) < 0) then        begin              Self.ERROR_FUNC_CODE := FUNC_CODE_BIND;                Self.SOCKET_ERROR_CODE := SocketError;                Self.Terminate;                exit;        end;        if (fpListen(Self.ListenSocket, Self.srv_backlog + 1) < 0) then        begin                Self.ERROR_FUNC_CODE := FUNC_CODE_LISTEN;                Self.SOCKET_ERROR_CODE := SocketError;                Self.Terminate;                exit;        end;        thrargs.socket_to_listen := Self.ListenSocket;        thrargs.bufsize := Self.CLIENT_BUFFER_SIZE;        thrargs.client_received_callback := Self.srv_client_received_callback;        thrargs.client_error_callback := Self.srv_client_error_callback;      thrargs.client_closed_callback := Self.srv_client_closed_callback;      thrargs.client_sent_callback := Self.srv_client_sent_callback;end; procedure TTCPIPServerThread.Execute;const ref: array[0..3] of char = ('N', '/', 'A', #0);var        i: integer;        f: boolean;        fe, se: longint;        ClientAddr: TInetSockAddr;        ClientAddrSize: LongInt;        ClientSocket: Longint;begin        ClientAddrSize := SizeOf(ClientAddr);        while (not Self.Terminated) do        begin                fpFD_Zero(Self.FDS);                fpFD_Set(Self.ListenSocket, Self.FDS);                fpSelect(Self.ListenSocket + 1, @(Self.FDS), nil, nil, 5000);              if ((not Self.Terminated) and (fpFD_ISSET(Self.ListenSocket, Self.FDS) <> 0)) then                begin                        f := false;                        for i := 0 to Self.client_count - 1 do                      begin                                if (Self.clients[i].Finished) then                                begin                                      f := true;                                      break;                                end;                      end;                        if (f) then                      begin                                Self.clients[i].Free;                      end                        else                        begin                                f := Self.client_count < Self.srv_backlog;                                if (f) then                              begin                                        i := Self.client_count;                                        inc(Self.client_count);                                        setlength(Self.clients, Self.client_count);                              end;                        end;                        if (f) then                        begin                                Self.last_client := i;                                thrargs.client_index := Self.last_client;                              Self.clients[Self.last_client] := TTCPIPServerCommThread.Create(@thrargs);                              Self.GetClientLastError(Self.last_client, @fe, @se);                              if ((Self.srv_client_created_callback <> nil) and (fe = 0)) then                                begin                                      Self.srv_client_created_callback(@(Self.clients[Self.last_client]));                              end;                        end                      else                        begin                              ClientSocket := fpaccept(Self.ListenSocket, @ClientAddr, @ClientAddrSize);                                if (ClientSocket >= 0) then                                begin                                      fpSend(ClientSocket, @ref[0], 4, 0);                                      CloseSocket(ClientSocket);                              end;                        end;                end;        end;        CloseSocket(Self.ListenSocket);end; procedure TTCPIPServerThread.GetLastError(func_error: plongint; socket_error: plongint);begin        func_error^ := Self.ERROR_FUNC_CODE;        socket_error^ := Self.SOCKET_ERROR_CODE;end; procedure TTCPIPServerThread.GetClientLastError(index: longint; func_error: plongint; socket_error: plongint);begin        if (index < Self.client_count) then        begin                Self.clients[index].GetLastError(func_error, socket_error);        end;end; function TTCPIPServerThread.ClientCount: longint;begin      Result := Self.client_count;end; function TTCPIPServerThread.LastCreatedClient: longint;begin        Result := Self.last_client;end; procedure TTCPIPServerThread.RecvAck(index: longint);begin        if (index < Self.client_count) then        begin                Self.clients[index].RecvAck;        end;end; function TTCPIPServerThread.BufferContentSize(index: longint): longword;begin        if (index < Self.client_count) then      begin                Result := Self.clients[index].BufferContentSize;        end;end; function TTCPIPServerThread.BufferPointer(index: longint): pbyte;begin        if (index < Self.client_count) then        begin                Result := Self.clients[index].Buffer;        end;end; procedure TTCPIPServerThread.Send(index: longint; buf: pbyte; size: longword);begin        if (index < Self.client_count) then        begin                Self.clients[index].OutBuf := buf;              Self.clients[index].OutBufSize := size;        end;end; function TTCPIPServerThread.OutBufferEmpty(index: longint): boolean;begin      if (index < Self.client_count) then        begin                Result := Self.clients[index].OutBufSize = 0;        end;end; procedure TTCPIPServerThread.FinishServer(HaltTime: longword);var        count: longword;        i: integer;begin        if (Self.Finished or Self.Terminated) then        begin              exit;        end;         for i := 0 to Self.client_count - 1 do      begin                Self.clients[i].FinishClient(HaltTime);        end;        setlength(Self.clients, 0);        count := (HaltTime div 50) + 1;        Self.Terminate;        while ((not Self.Finished) and (count > 0)) do        begin                fpnanosleep(@(Self.ts0), @(Self.ts1));                dec(count);        end;end; end.  The weirdest part is, that the problem is gone now. In the other thread there was an fpnanosleep() with the interval of 1000000 nanosec. I replaced that to sleep(1). And now it works. Which is incomprehensible. At least for me. ---------------------------------------------------------------------- TCH · 2018-08-29 10:22 It still trashes one variable in the same array, but now it is a different element, what is not affected right now, that's why the program worked in the morning. How can a thread crash a variable in the main thread, during a third thread's fpselect? ---------------------------------------------------------------------- Thaddy · 2018-08-29 10:22 Quote from: TCH on August 29, 2018, 10:12:54 amNo, the compiler gives no warnings. The linker gives the usual warning: "link.res contains output sections; did you forget -T?" That means your FPC is old... From 3.0.4 that warning is gone... ---------------------------------------------------------------------- Thaddy · 2018-08-29 10:28 Quote from: TCH on August 29, 2018, 10:12:54 amThe weirdest part is, that the problem is gone now. In the other thread there was an fpnanosleep() with the interval of 1000000 nanosec. I replaced that to sleep(1). And now it works. Which is incomprehensible. At least for me. Not THAT weird: the requirements for fpnanosleep are rather specific and (as I wrote before) you should check for errors, which you didn't do (again) . http://man7.org/linux/man-pages/man2/nanosleep.2.html ---------------------------------------------------------------------- TCH · 2018-08-29 11:35 Quote from: Thaddy on August 29, 2018, 12:22:35 pmQuote from: TCH on August 29, 2018, 10:12:54 amNo, the compiler gives no warnings. The linker gives the usual warning: "link.res contains output sections; did you forget -T?" That means your FPC is old... From 3.0.4 that warning is gone... 3.0.2. One version older than the current stable.Quote from: Thaddy on August 29, 2018, 12:28:27 pmQuote from: TCH on August 29, 2018, 10:12:54 amThe weirdest part is, that the problem is gone now. In the other thread there was an fpnanosleep() with the interval of 1000000 nanosec. I replaced that to sleep(1). And now it works. Which is incomprehensible. At least for me. Not THAT weird: the requirements for fpnanosleep are rather specific and (as I wrote before) you should check for errors, which you didn't do (again) . http://man7.org/linux/man-pages/man2/nanosleep.2.html There was a second post, which states, that it still trashes a variable in another thread. Also, i removed all of the fpnanosleeps from the project and the problem still persists. ---------------------------------------------------------------------- TCH · 2018-08-29 11:59 I prevented the network event and the variable is still trashed by the other thread. So the TCP/IP server is innocent. But i cannot publish that thread as it is contains company related stuff. ---------------------------------------------------------------------- Thaddy · 2018-08-29 13:33 Quote3.0.2. One version older than the current stable. yes, so you missed the version where that bogus warning was fixed..... If a thread thrashes something it is the thread that is at fault and you should go over your code very carefully. This is not in anyway FPC or ARM related. It may simply be that an Intel/amd is a little more forgiving with atomicity than arm is. Try to use interlocked* functions for writing to a shared var. Note that I suspect that you will run into trouble on Intel/Amd too sooner or later. Those bugs will eventually manifest themselves. Can you tell me the type and the size of the var that gets thrashed? Then I can either tell you operations on it can be assumed atomic or show you how to handle it. Example: a 64 bit integer write is atomic on intel64 but not on Intel32 or arm32. On those you need either one of the interlocked functions or cannons like a TMultipleReadExclusiveWriteSynchronizer or a TCriticalSection. (Oh, and did I mention to check for errors when using kernel/OS calls? < >) ---------------------------------------------------------------------- TCH · 2018-08-29 14:00 You say, i ran into a compiler bug? I did not touch that variable from anywhere! That variable is initialized in the beginning and then the stored values are loaded from config. After that nothing touches it. It is not a shared variable. Also, my thread uses exactly zero shared variable. It stores everything in the thread and outsited the thread i get the results via getters. Yes, i can tell the variable's structure:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         WR: array[0..3] of record                RelayTime: longword;              RelayDelayTime: longword;                RelaySensorTime: longword;                RelayNormalOpen: boolean;                DirInWGID: byte;                DirInUSBKBID: byte;                DirOutWGID: byte;                DirOutUSBKBID: byte;        end;This variable is wrecked at some point. First it was WR[0].RelayTime, now it is WR[2].RelayDelayTime. It changed, when i have thrown out the fpnanosleep from the other thread. The variable is in the interface of another unit (namely the config). Neither of the two units has the other in the uses list. ---------------------------------------------------------------------- Thaddy · 2018-08-29 14:44 Such a structure is NOT thread safe. That definitely needs to be guarded with a critical section. Is it? (That goes for any language, not just Pascal!) Note my assessment was right: you were just lucky on Intel.... ---------------------------------------------------------------------- TCH · 2018-08-29 15:00 Why? How can a thread ruin it which is not connected to it in any way? I would understand it if there would be some pointer operations, but there aren't. (Aside from the GPIO read/write, but if that would be erroneous, then the GPIO operations would not work.) ---------------------------------------------------------------------- TCH · 2018-08-29 15:48 Okay, i think i found it. I made a checker which checked if the array differs from the original and inserted before and after all the relevant lines in the thread. And it wasn't the thread. It was the callback function in the main program. I forgot to check if the passed index is smaller than 9 so i overindexed a different array from a different unit. The only thing i don't understand, should not Pascal give a SEGFAULT then? ---------------------------------------------------------------------- Thaddy · 2018-08-29 15:53 No, that depends. But did you use {$Rangechecks on} during debugging? Not! Still, don't blame the callback too soon: that structure needs protection when it is used as an instance accessible to multiple threads.. ---------------------------------------------------------------------- TCH · 2018-08-29 16:05 Well, i did not, but until this moment, whenever i made a similar mistake, i was always rewarded with a SIGSEGV. I just assumed, that it is how array indexing in Pascal works. Thanks for $Rangechecks tip. I don't blame anything, the blame is mine. But the problem is solved. How can i protect the structure other than validating array indexes? ---------------------------------------------------------------------- lucamar · 2018-08-29 16:20 Quote from: Thaddy on August 29, 2018, 12:22:35 pmQuote from: TCH on August 29, 2018, 10:12:54 amNo, the compiler gives no warnings. The linker gives the usual warning: "link.res contains output sections; did you forget -T?" That means your FPC is old... From 3.0.4 that warning is gone... Uhh .. Thaddy, I'm using 3.0.4  and the warning is still there (at least in Linux). Does it not depend rather on the version of ld (the linker)? ---------------------------------------------------------------------- Thaddy · 2018-08-29 16:50 Quote from: lucamar on August 29, 2018, 06:20:43 pmUhh .. Thaddy, I'm using 3.0.4  and the warning is still there (at least in Linux). Does it not depend rather on the version of ld (the linker)? There's a very slight chance it is just in 3.2.0 but I really think the linker behavior has changed since 3.0.4. provided you have an up- to-date linker. 2.21 won't do. More in detail: FPC changed the way it talks to the linker and the warning is harmless.