I am developing an application in which I must handle some lists (insertion, deletion). The problem is that the list can suffer alteration from a TTimer component and from a TServerSocket.
How can I protect the lists from being altered by the TTimer and the TServerSocket at the same time? Should I use threads?
Timer events are running in the application’s main thread. I am not sure about TServerSocket events (may be a configuration option).
Generally: If both accesses are running in the main thread, you do not need a critical section because the other event can only fire when the first event has already finished (unless you call Application.ProcessMessages which you shouldn’t anyway). A critical section wouldn’t work in this scenario any way because it will only sync separate threads.
If they are running in different threads, you need some kind of synchronization. A critical section is one option, others include Mutexes, spin locks etc.