huh threads and sync well known since 1st computers? Okay FIFO containers (First in First Out rolling buffers, yes), but synchronizing while entries can arrive faster than computed outgoing result, NOWAY
I don't want a trial from what you smoke lately LOL when you comment
FBuffer:TThreadededQueue<TStringList>;//Simple example - it's not that hard to construct such container by yourself
HAHAHAH
Yeah, what TS needs - is actually interrupt handler. Something similar to keyboard interrupt handler. You know, yeah, interrupt handlers were first way to implement hardware multitasking and multithreading. Actually, even on moderns OSs when you have only one core - threads are being switched in timer interrupt handler. What keyboard interrupt was? It was "Interrupt current process, read key from keyboard and then store it to buffer, so keys won't be lost, if main thread won't be able to read them before next keyboard event would occur". TS needs exactly the same.
And there is simple way to emulate interrupt - threads. Thread waits for event from hardware, than puts data to queue, so data won't be lost, if next hardware event will occur before main thread would be able to handle previous one, and then main thread pulls data from this queue. Queue - is the only global object in this case and it is blocked only during reading/writing - not during whole data processing in main thread. Two things are being done at the same time - maximum thread effectivity. Cuz thread is useless, if you block it to do something in main thread - you shouldn't even use thread in this case.
What thread should do:
while not Terminated do begin
Data := ReadData;
EnterCriticalSection;
Queue.Push(Data);
LeaveCriticalSection;
end;
What main thread should do to read data:
EnterCriticalSection;
Data := Queue.Pull;
LeaveCriticalSection;
If you don't know, how to implement queue - it's looped buffer. Yeah, you can implement stack via list, but queue would require too much data copying in this case. And of course I won't do it for you. I just used simple example, where fully featured object, made specifically for this purpose, is used. But again, it's not that hard to implement looped buffer + critical section to sync access to it by yourself.