OK lets go with the code provided, the main problem I see is that you make assumptions on the synchronization of the thread and the main thread execution time. You say that it should be true after the call to end update but I do not see anywhere code that makes sure that the thread had enough time to reach and execute the code <test_flag:= true;> at all, depending on the number of tests you might have different results each time why not introduce a sleep(X) before checking the test_flag where X must be equal to the total time required to execute a single iteration inside the while loop.
Still the code you provide is not enough for example how is the test_flag declared is it var or threadvar? inside the form or global to the unit/application, as you can see there are a number of reasons that your test fails and the thread is still executing behind your back so a complete demo that shows the problem with everything visible would be better for us to test.
Thanks taazz
The test_flag is a global variable, not a thread var. I hered somewhere that boolean vars don't need to be defines in 'Critical Section'.
I can't add a Sleep(x) to main thread, because this don't change EndUpdate problem!
I attached the my test code. I am waiting any suggestion.
Thanks CaptBill (Great man of TinyCore)
Since you are already dealing with GPIO pins you could simply pass the data to a micro controller for buffering and timing. There is no need for 'Preempting', 'blocking', 'locks','priorities' etc. etc. Those are all 'contentious' types of coding where you are fighting the system for powers that aren't normally allowed. Those are all 'work arounds' to a problem that even the little Rasberry Pi OS has: poor 'real-time' skills. Micro controllers don't have those problems.
Yes, Doing this job with MCUs is 'ULTRA SIMPLE'. But I come from there to use a 1GHz CPU!!!
Recent years, I made many boards with AVR + WIN PC + Wireless dongle (that i made by NRF24L01+). Everything works OK.
I removed AVR, Wirless Link and connect all ICs directly to GPIO of Raspberry Pi. This Reduces the board size and eliminate an expensive Windows PC.
I expect the 1GHz CPU works better than a 20MHz AVR!
Linux has many advantages over Windows but I disappointed, If i can't have a simple interrupt (or fixed time thread)
My last solution is to:
1- Add an AVR to the board and buffer 100 samples
2- Add a 1 Sec timer in Lazarus Program
3- In the on timer event handler, simultaneously read all 100 samples from SPI and add them to LineSeries of chart.
This is very simple, but was not my first goal
Regards