Bug or Feature? TApplication.ProcessMessages vs. TThread.Synchronize lazarus / 31-LCL ---------------------------------------------------------------------- Pascal · 2018-07-27 05:56 I have a thread class which updates the GUI (TSynEdit) by calling a synchronized method (updating a XRef-List after parsing source files). So far so good. If one instance runs i can still use the GUI but if there is more than one instance the GUI is unusable until there is only one thread left doing some work. Is this a bug or a feature? I can add Application.ProcessMessages in the synchronized method but then all instances do not work in parallel anymore. Instead they get done in big bunches for each thread. Any ideas to solve this? ---------------------------------------------------------------------- taazz · 2018-07-27 06:14 Quote from: Pascal on July 27, 2018, 07:56:35 amI have a thread class which updates the GUI (TSynEdit) by calling a synchronized method (updating a XRef-List after parsing source files). So far so good. If one instance runs i can still use the GUI but if there is more than one instance the GUI is unusable until there is only one thread left doing some work. Is this a bug or a feature? Depends 1) how often do you update? 2) How long it takes for the update to execute? 3) have you tried QueueAsyncCall? Will this also freeze the application? Quote from: Pascal on July 27, 2018, 07:56:35 amI can add Application.ProcessMessages in the synchronized method but then all instances do not work in parallel anymore. Instead they get done in big bunches for each thread. Any ideas to solve this? No its not the application.processmessages that has that effect its more likely that it only makes it visible. From your description I would say that the synchronization queue is getting new entries faster than it is able to process them. Try to make the update interval bigger in your threads eg instead of calling synchronize when a step has finished call it every second or two, does it have the same effect? It should be faster to finish this way too. In general it is more user friendly to run update on time intervals instead of milestones. ---------------------------------------------------------------------- Pascal · 2018-07-27 07:03 Quote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI have a thread class which updates the GUI (TSynEdit) by calling a synchronized method (updating a XRef-List after parsing source files). So far so good. If one instance runs i can still use the GUI but if there is more than one instance the GUI is unusable until there is only one thread left doing some work. Is this a bug or a feature? Depends 1) how often do you update? 2) How long it takes for the update to execute? 3) have you tried QueueAsyncCall? Will this also freeze the application? 1) The update is done when the parsing of the sources has finished (after esiting one of the sources) and then for each entry of each XRef.     So that the XRefs reflect the current state of the sources as fast as possible while not influencing the user in editiing the sources. 2) Depends on the count of refs. Approx 4s for 1000 refs 3) not tried yet as the working procedure depends on many thread internals Quote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI can add Application.ProcessMessages in the synchronized method but then all instances do not work in parallel anymore. Instead they get done in big bunches for each thread. Any ideas to solve this? No its not the application.processmessages that has that effect its more likely that it only makes it visible. From your description I would say that the synchronization queue is getting new entries faster than it is able to process them. I think the problem is that while there are pending synchronize method they are handled until the queue is empty instead of taking one, handle meessages and then takte the next synchronized method and so on. I tried to modify TWin32WidgetSet.AppProcessMessages and CheckSynchronize. But no success so far. Quote from: taazz on July 27, 2018, 08:14:00 amTry to make the update interval bigger in your threads eg instead of calling synchronize when a step has finished call it every second or two, does it have the same effect? It should be faster to finish this way too. In general it is more user friendly to run update on time intervals instead of milestones. As the updates take some time, they have to be done in small chunks anyway. So if implementation of Synchronize and QueueAsyncCall is correct it shouldn't make any difference as both are called in the context of the main tread. As stated above the problem seems to be the kind how the synchronized methods are handled. ---------------------------------------------------------------------- PascalDragon · 2018-07-27 07:16 It's not a good idea to call Application.ProcessMessages inside a synchronized function as that will again call CheckSynchronize which might lead to unexpected behavior. As a rule of thumb synchronized methods should be short and to the point, there shouldn't be any need to call Application.ProcessMessages inside them. ---------------------------------------------------------------------- Pascal · 2018-07-27 07:24 Quote from: PascalDragon on July 27, 2018, 09:16:21 amIt's not a good idea to call Application.ProcessMessages inside a synchronized function as that will again call CheckSynchronize which might lead to unexpected behavior. As a rule of thumb synchronized methods should be short and to the point, there shouldn't be any need to call Application.ProcessMessages inside them. Mine are short! But the problem arrises when more than one thead is calling Synchronize consecutively. ---------------------------------------------------------------------- taazz · 2018-07-27 07:31 Quote from: Pascal on July 27, 2018, 09:03:56 amQuote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI have a thread class which updates the GUI (TSynEdit) by calling a synchronized method (updating a XRef-List after parsing source files). So far so good. If one instance runs i can still use the GUI but if there is more than one instance the GUI is unusable until there is only one thread left doing some work. Is this a bug or a feature? Depends 1) how often do you update? 2) How long it takes for the update to execute? 3) have you tried QueueAsyncCall? Will this also freeze the application? 1) The update is done when the parsing of the sources has finished (after esiting one of the sources) and then for each entry of each XRef.     So that the XRefs reflect the current state of the sources as fast as possible while not influencing the user in editiing the sources. 2) Depends on the count of refs. Approx 4s for 1000 refsNot the process the method to put it simple you call synchronise(myMethod) from the moment the main start executing MyMethod how long it takes to complete? I'm trying to help you pin point where is the delay. Quote from: Pascal on July 27, 2018, 09:03:56 am3) not tried yet as the working procedure depends on many thread internals erm ok, I have no idea what that means but I'll take your word for it. Quote from: Pascal on July 27, 2018, 09:03:56 amQuote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI can add Application.ProcessMessages in the synchronized method but then all instances do not work in parallel anymore. Instead they get done in big bunches for each thread. Any ideas to solve this? No its not the application.processmessages that has that effect its more likely that it only makes it visible. From your description I would say that the synchronization queue is getting new entries faster than it is able to process them. I think the problem is that while there are pending synchronize method they are handled until the queue is empty instead of taking one, handle meessages and then takte the next synchronized method and so on. I tried to modify TWin32WidgetSet.AppProcessMessages and CheckSynchronize. But no success so far. Quote from: taazz on July 27, 2018, 08:14:00 amTry to make the update interval bigger in your threads eg instead of calling synchronize when a step has finished call it every second or two, does it have the same effect? It should be faster to finish this way too. In general it is more user friendly to run update on time intervals instead of milestones. As the updates take some time, they have to be done in small chunks anyway. So if implementation of Synchronize and QueueAsyncCall is correct it shouldn't make any difference as both are called in the context of the main tread. There is a big difference and you should know by now. In the first case (synchronize) the thread continues only after the main thread has finished executing the method in question in the second case (QueueAsyncCall) the thread continues to add updates regardless of the state of execution of the main and the queued methods. What that means is in the second case the thread's speed penalty is smaller but the queue backup will be grater as the execution time for the method queued becomes bigger, that means that its conceivable that the thread finished its work but the main thread has not had the time to process the all the updates yet. In Quote from: Pascal on July 27, 2018, 09:03:56 amAs stated above the problem seems to be the kind how the synchronized methods are handled. No both use the same queue mentality I do not remember if the synchronization releases each thread imidiatly after its method is executed or if it waits until all synchronized methods are executed before releasing them all together to continue their work. In any case you know you can write your own synchronization methodology right? You only have to add a handler for the application.onidle event and in there use your own method queue to execute what ever it was registered from your threads in any way you see fit. ---------------------------------------------------------------------- Pascal · 2018-07-27 08:05 Quote from: taazz on July 27, 2018, 09:31:40 amQuote from: Pascal on July 27, 2018, 09:03:56 amQuote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI have a thread class which updates the GUI (TSynEdit) by calling a synchronized method (updating a XRef-List after parsing source files). So far so good. If one instance runs i can still use the GUI but if there is more than one instance the GUI is unusable until there is only one thread left doing some work. Is this a bug or a feature? Depends 1) how often do you update? 2) How long it takes for the update to execute? 3) have you tried QueueAsyncCall? Will this also freeze the application? 1) The update is done when the parsing of the sources has finished (after esiting one of the sources) and then for each entry of each XRef.     So that the XRefs reflect the current state of the sources as fast as possible while not influencing the user in editiing the sources. 2) Depends on the count of refs. Approx 4s for 1000 refsNot the process the method to put it simple you call synchronise(myMethod) from the moment the main start executing MyMethod how long it takes to complete? I'm trying to help you pin point where is the delay. Min: 1,833 ms Max: 25,777 ms Avg: 5,647 ms Count: 198 Quote from: taazz on July 27, 2018, 09:31:40 amQuote from: Pascal on July 27, 2018, 09:03:56 am3) not tried yet as the working procedure depends on many thread internals erm ok, I have no idea what that means but I'll take your word for it. Quote from: Pascal on July 27, 2018, 09:03:56 amQuote from: taazz on July 27, 2018, 08:14:00 amQuote from: Pascal on July 27, 2018, 07:56:35 amI can add Application.ProcessMessages in the synchronized method but then all instances do not work in parallel anymore. Instead they get done in big bunches for each thread. Any ideas to solve this? No its not the application.processmessages that has that effect its more likely that it only makes it visible. From your description I would say that the synchronization queue is getting new entries faster than it is able to process them. I think the problem is that while there are pending synchronize method they are handled until the queue is empty instead of taking one, handle meessages and then takte the next synchronized method and so on. I tried to modify TWin32WidgetSet.AppProcessMessages and CheckSynchronize. But no success so far. Quote from: taazz on July 27, 2018, 08:14:00 amTry to make the update interval bigger in your threads eg instead of calling synchronize when a step has finished call it every second or two, does it have the same effect? It should be faster to finish this way too. In general it is more user friendly to run update on time intervals instead of milestones. As the updates take some time, they have to be done in small chunks anyway. So if implementation of Synchronize and QueueAsyncCall is correct it shouldn't make any difference as both are called in the context of the main tread. There is a big difference and you should know by now. In the first case (synchronize) the thread continues only after the main thread has finished executing the method in question in the second case (QueueAsyncCall) the thread continues to add updates regardless of the state of execution of the main and the queued methods. What that means is in the second case the thread's speed penalty is smaller but the queue backup will be grater as the execution time for the method queued becomes bigger, that means that its conceivable that the thread finished its work but the main thread has not had the time to process the all the updates yet. In Yes, i know,  that's why i can't switch to QueueAsyncCall that easy as the thread (with the needed data) could be dead already. I have to put the data together for each method first. Quote from: taazz on July 27, 2018, 09:31:40 amQuote from: Pascal on July 27, 2018, 09:03:56 amAs stated above the problem seems to be the kind how the synchronized methods are handled. No both use the same queue mentality I do not remember if the synchronization releases each thread imidiatly after its method is executed or if it waits until all synchronized methods are executed before releasing them all together to continue their work. In any case you know you can write your own synchronization methodology right? You only have to add a handler for the application.onidle event and in there use your own method queue to execute what ever it was registered from your threads in any way you see fit. Yes, i know, but neither this nor QueueAsyncCall would be needed if handling synchronized methods would be handled in correct manner with more than one thread issuing calls to Synchronize! ---------------------------------------------------------------------- taazz · 2018-07-27 08:27 Quote from: Pascal on July 27, 2018, 10:05:22 amMin: 1,833 ms Max: 25,777 ms Avg: 5,647 ms Count: 198 nothing extreme here it should be ok. Which means that you call synchronize too many times. Add a time delay of 250ms between calls to synchronize see how/if  that helps . Oh by time delay I mean change the call to synchronize to something along the lines of 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 ...  if lastExecute > 0 then timeElapsed := gettickcount - lastexecute else timeElapsed :=250;//ms  if timeEllapsed >=250{ms} then begin      synchronize(........      lastExecute := gettickcount;   end;... see if that helps. Quote from: Pascal on July 27, 2018, 10:05:22 amYes, i know, but neither this nor QueueAsyncCall would be needed if handling synchronized methods would be handled in correct manner with more than one thread issuing calls to Synchronize! Ok I'll byte, what is the correct manner? ---------------------------------------------------------------------- Pascal · 2018-07-27 08:36 Quote from: taazz on July 27, 2018, 10:27:02 amQuote from: Pascal on July 27, 2018, 10:05:22 amYes, i know, but neither this nor QueueAsyncCall would be needed if handling synchronized methods would be handled in correct manner with more than one thread issuing calls to Synchronize! Ok I'll byte, what is the correct manner? User first! First handling of messages before anything else to respond to user input as fast as possible and therefore only handle synchronized methods one by one and not all pending ones together. ---------------------------------------------------------------------- taazz · 2018-07-27 09:14 Quote from: Pascal on July 27, 2018, 10:36:16 amQuote from: taazz on July 27, 2018, 10:27:02 amQuote from: Pascal on July 27, 2018, 10:05:22 amYes, i know, but neither this nor QueueAsyncCall would be needed if handling synchronized methods would be handled in correct manner with more than one thread issuing calls to Synchronize! Ok I'll byte, what is the correct manner? User first! First handling of messages before anything else to respond to user input as fast as possible and therefore only handle synchronized methods one by one and not all pending ones together. unless ofcourse the updates are crucial for the end user (eg collision alarm) in which case waiting for the next iteration might be unacceptable. Sorry but your point of view is a bit restricted from your task at hand there are use cases that support your point of view and use cases that do not. As I already said you can write your own queue that can handle the updates in any way you see fit including removing all update of a single thread and only execute the last method in the queue of that thread to gain in speed even more. ---------------------------------------------------------------------- Pascal · 2018-07-27 09:59 Okay, i'll try to build my own. Thanks for your efforts! ---------------------------------------------------------------------- Martin_fr · 2018-07-27 10:46 The easiest may be to use Thread.Queue and then set your own event  (RTLeventWaitFor and related) to hold the thread until the event was processed. That is essentially what Synchronize does. But you get a tiny bit more control. In your event you could do: 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 DoEventWork;RTLeventSetEvent(ev);  // let the thread continueApplication.ProcessMessages; // Now the thread does not wait for this to finish  Of course you still have all the threads waiting that have an event in the queue. But that happens in any case. It would occur that handling the thread results in the main thread takes too much time. Better than the above, would be if the thread provides the data, in such a way that the thread can continue (or even be free'd). The main thread then frees the memory. Then the main thread can store the data, and handle it in small slices in Idle, or QueueAsync. ---------------------------------------------------------------------- Pascal · 2018-07-27 11:15 Quote from: Martin_fr on July 27, 2018, 12:46:39 pmThe easiest may be to use Thread.Queue and then set your own event  (RTLeventWaitFor and related) to hold the thread until the event was processed. That is essentially what Synchronize does. But you get a tiny bit more control. In your event you could do: 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 DoEventWork;RTLeventSetEvent(ev);  // let the thread continueApplication.ProcessMessages; // Now the thread does not wait for this to finish  Of course you still have all the threads waiting that have an event in the queue. But that happens in any case. It would occur that handling the thread results in the main thread takes too much time. Better than the above, would be if the thread provides the data, in such a way that the thread can continue (or even be free'd). The main thread then frees the memory. Then the main thread can store the data, and handle it in small slices in Idle, or QueueAsync. Thanks for the additional idea. The problem with bringing all to the main thread and handle it there is that not necessarily all work has to be done. For example when the user continues editing and the sources get parsed and then the XRefs have to be rebuild, a current running work of an XRef can be stopped/restarted instead of compleeting it first. If everything has been passed to the main thread it is still in the queue and will be processed to the end ---------------------------------------------------------------------- Pascal · 2018-07-27 12:03 Quote from: Martin_fr on July 27, 2018, 12:46:39 pmThe easiest may be to use Thread.Queue and then set your own event  (RTLeventWaitFor and related) to hold the thread until the event was processed. That is essentially what Synchronize does. But you get a tiny bit more control. In your event you could do: 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 DoEventWork;RTLeventSetEvent(ev);  // let the thread continueApplication.ProcessMessages; // Now the thread does not wait for this to finish  Just did a test with this as it was easy to implement. But here the GUI gets locked when more than one thread has queued a method as Application.ProcessMessages (inside the queued method) will pick (CheckSyncronized) the method from the second thread while the first thread queues another method ans os on As mentioned earlier it would be great if CheckSyncronized would only pick one Method and not the complete bunch. But even if i serialize CheckSynchronize there will be no message handling in betwen them. Don't know why (TWin32WidgetSet.AppProcessMessages)! ---------------------------------------------------------------------- Pascal · 2018-07-27 12:08 Quote from: Pascal on July 27, 2018, 02:03:48 pmBut even if i serialize CheckSynchronize there will be no message handling in betwen them. Don't know why (TWin32WidgetSet.AppProcessMessages)! Strange! Even if i put 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       while PeekMessage(AMessage, HWnd(nil), 0, 0, PM_REMOVE) do      begin      if AMessage.message = WM_QUIT then        begin          PostQuitMessage(AMessage.wParam);          break;        end;        TranslateMessage(@AMessage);        DispatchMessageW(@AMessage);      end; After the modified CheckSynchronized (handles only the first method) there seem to be no messages even though i am moving cursor or typing! ---------------------------------------------------------------------- Martin_fr · 2018-07-27 13:21 Quote from: Pascal on July 27, 2018, 02:03:48 pmQuote from: Martin_fr on July 27, 2018, 12:46:39 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DoEventWork;RTLeventSetEvent(ev);  // let the thread continueApplication.ProcessMessages; // Now the thread does not wait for this to finish  Just did a test with this as it was easy to implement. But here the GUI gets locked when more than one thread has queued a method as Application.ProcessMessages (inside the queued method) will pick (CheckSyncronized) the method from the second thread while the first thread queues another method ans os on As mentioned earlier it would be great if CheckSyncronized would only pick one Method and not the complete bunch. But even if i serialize CheckSynchronize there will be no message handling in betwen them. Don't know why (TWin32WidgetSet.AppProcessMessages)! Application.ProcessMessages first does the messages (keydown etc..>), then it does the next checkSyncronize. However: - If your mainthread is busy, then paint events can be skipped (but that would apply even in your modified loop) - you risk a very deep stack recursion, in fact you can run out of stack QuoteThe problem with bringing all to the main thread and handle it there is that not necessarily all work has to be done. For example when the user continues editing and the sources get parsed and then the XRefs have to be rebuild, a current running work of an XRef can be stopped/restarted instead of compleeting it first. If everything has been passed to the main thread it is still in the queue and will be processed to the end SynEdit has a changestamp, if you include that in the produced data, then you can skip processing data, if the synedit was changed since. You can do your own more finegrained validation. E.g. hook OnStatusChange, and record the lowest line number in which changes where made. ------------------ In any case, as long as you use Syncronize, or waitForEvent, your threads will be in suspended state for some time. If 5 threads call Sync (or wait), with data, that takes 4 secs in the mainthread - and even if the main thread does process messages - then the last of the 5 threads will wait until its sync call returns. And that sync call must wait, until the 4 others have finished (that is 16 seconds). So in that time the thread can not do new work. Whereas, if you just send the date with Thread.Queue, the thread resumes immediately. The data can have some validation stamp, so the main thread knows if it is still ok. The main thread can process the data, in chunks, and check the state. In fact, you only need Thread.Queue as a trigger for the main thread to start picking up. You can share the data, and use TRTLCriticalSection to ensure correct access. If the thread has a (linked) list, of small chuncks, then the  main thread enters a TRTLCriticalSection and gets the first chunk. (removes it from the list). The thread still can access all the other chunks (but must do so in a TRTLCriticalSection too) ---------------------------------------------------------------------- Pascal · 2018-07-27 13:34 Quote from: Martin_fr on July 27, 2018, 03:21:14 pmApplication.ProcessMessages first does the messages (keydown etc..>), then it does the next checkSyncronize. However: - If your mainthread is busy, then paint events can be skipped (but that would apply even in your modified loop) - you risk a very deep stack recursion, in fact you can run out of stack If i leave CheckSynchronized after handling one method (modified version) AppProcessMessages should have been called again. But no messages get handled until only one thread is using Synchronize. It behaves the same as the unmodified CheckSynchronize! That's what i do not understand. Why aren't there any messages of my user interaction? Where do they get stuck? ---------------------------------------------------------------------- Martin_fr · 2018-07-27 15:56 But debugln statements (uses LazLogger) into the loop, and at any place of interest. Compile your app without -WG  (gui app) or even add -WC (console). Then you can watch in the console what happens. ----------- Only use debugln in the main thread. In trunk it is threadsave, but use Syncronize. So you can change the class, to use critical sections, by editing LazLogger. Btw: Which OS/Widgetset? ---------------------------------------------------------------------- Pascal · 2018-07-27 16:51 Quote from: Martin_fr on July 27, 2018, 05:56:11 pmBtw: Which OS/Widgetset? Win10 1803 ---------------------------------------------------------------------- Martin_fr · 2018-07-27 18:11 Well, have a look at TLazLoggerFileHandleMainThread.WriteLnToFile in unit LazLogger. It appends the info (here the text to be logged, but can be anything) to a linked list. The main thread (triggered vie Thread.Queue) fetches data from this list, and frees the memory In LazLogger, the entire linked list is taken by the mainthread within the critical section. In your case you only take the first item. So the thread can still change all other entries (but only in a critical section!). The main thread does not have to do all the work in Thread.Queue, it could do some, and then schedule an application.QueueAsync. If you take care, and only change the linking pointers in the critical section, then the time any thread may wait for the link, will be minimal. If a thread wants to review the existing list, it simple removes all entries while in the critical section (just remove the entry pointer), leaves the critical section, does the work, and adds the list back (in a critical section) That way you should have full control of all aspects. ---------------------------------------------------------------------- taazz · 2018-07-27 22:51 Quote from: Pascal on July 27, 2018, 02:08:56 pmStrange! Even if i put 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       while PeekMessage(AMessage, HWnd(nil), 0, 0, PM_REMOVE) do      begin      if AMessage.message = WM_QUIT then        begin          PostQuitMessage(AMessage.wParam);          break;        end;        TranslateMessage(@AMessage);        DispatchMessageW(@AMessage);      end; After the modified CheckSynchronized (handles only the first method) there seem to be no messages even though i am moving cursor or typing! Quote from: Pascal on July 27, 2018, 03:34:41 pmIf i leave CheckSynchronized after handling one method (modified version) AppProcessMessages should have been called again. modified how exactly? checksynchronize has no loop in lazarus 1.4.4 I doubt it has changed in later versions. In any case you need to re compile the rtl for the changes to take effect, usually done while building fpc, or copy the classes unit and its inc files to you application's directory to force a newer version, that comes with its own can of worms, some could eat you all too. ---------------------------------------------------------------------- Pascal · 2018-07-28 05:56 Quote from: taazz on July 28, 2018, 12:51:39 ammodified how exactly? checksynchronize has no loop in lazarus 1.4.4 I doubt it has changed in later versions. In any case you need to re compile the rtl for the changes to take effect, usually done while building fpc, or copy the classes unit and its inc files to you application's directory to force a newer version, that comes with its own can of worms, some could eat you all too. Well, taazz, right,  that will be the problem: I have to reccomlipe fpc, which i didn't! (Could only be something dumb) In trunk CheckSynchronized loops through all available methods and returns then to the loop in AppProcessMessages and leaves the loop. ---------------------------------------------------------------------- taazz · 2018-07-28 06:24 Quote from: Pascal on July 28, 2018, 07:56:27 amWell, taazz, right,  that will be the problem: I have to reccomlipe fpc, which i didn't! (Could only be something dumb) don;t know about dump I have never successfully compiled fpc manually so I always opt on copying the changed unit in my app's directory. Me and cmd not very good combination. ---------------------------------------------------------------------- Pascal · 2018-07-28 06:32 I just did a test with limiting the access to Synchronize to one thread at a time and eveything works as exprected  All threads running in parallel while beeing able to continue editing.  But i still think the behavoiur of ChechSynchronize/AppProcessMessages is wrong at the moment.