Multithreading Considerations

The main reason why you want to use threads is to allow tasks to occur simultaneously in the foreground and the background. However, there are several considerations to keep in mind when using threads in ATEasy.

Any time that you use multiple threads, the threads have to be synchronized, in order to protect data and resources. Doing otherwise could lead to the corruption of data and/or inconsistent behavior in your program. One example which keeps coming up is when you have a string and two threads are trying to assign different values to it. Every time you assign a value to a string, the string space has to be re-allocated. When two threads attempt to assign different values at once, this could result in an undefined string which could crash ATEasy. For this reason, you have to use a synchronization object like a Critical Section to lock the string while one thread is changing it or using it, so that the other threads cannot access it. This will protect your data from being changed in unintended ways.