The computer has gone a long way compared to now. Modern computers have several CPU cores or CPUs. We utilize these cores to create high-volume applications. This week I read a blog discussing concurrency in programming. This blog, “Concurrent Programming – Introduction” by Gowthamy Vaseekaran, defines concurrency as the ability to run several programs or several parts of a program in parallel. Vaseekaran then goes further by saying that programs that take longer to perform certain tasks can benefit from using concurrency and that tasks can be done in parallel or asynchronously. This will, for the most part, upgrade the performance of the program. Vaseekaran also goes on to say that computers didn’t have operating systems back in the day, so single programs were executed from start to end. These programs had access to all the resources of the machine. Nowadays, executing a single program at a time is seen as an inefficient use of expensive and a waste of computer resources.
Several factors led to the development of operating systems that allowed multiple programs to run, such as resource utilization, the author explains that programs must wait for external operations, so using that time to let another program run was way more efficient. Fairness would allow multiple users and programs to have equal claims on a machine’s resources. It is fairer to let them share the computer rather than having one program run from start to end and then another. Also having convenience is very neat, so that several programs can coordinate to perform a single task. It’s interesting while reading this because currently I’m taking a class on algorithms, and so in this class, we will discuss how some programs will take longer than others. There is the worst solution to how a problem or program in this case should be run, and the best solution. Concurrency could fit into making programs run more efficiently.
The author then goes on to discuss computer threads which are a facility to allow multiple activities within a single process, a series of executed statements, a nested sequence of method calls, etc. We use threads to help perform background or asynchronous processing. The thread takes advantage of multiprocessor systems, and it simplifies program logic when there are multiple independent entities. Java will utilize threads very often. Every Java program creates at least one thread.
Threads can also pose risks; the main problem is the shared variable/resource problem. Solutions for this problem include not sharing any variables, making variables immutable which is the process of making variables unchangeable to their value or state, and using a lock. A lock is a thread synchronization mechanism in java. Another problem includes race condition which is the most common concurrency correctness problem, which pays attention to compound actions, which is when two threads access a shared variable at the same time. Vaseekaran also goes on to explain deadlocking which is a condition where two or more threads are blocked forever, waiting for each other. Deadlocks are caused by inconsistent lock ordering and limitation of resource capacity when a thread is waiting for another lock.
It’s very interesting to see how important concurrency is when it comes to making or even running programs, it brings a whole new understanding of how modern programs work. It’s also interesting to hear about terms such as “deadlock” because it’s a refresher of what it means and what role it plays when talking about concurrency. Reading about how computers used to run programs gives me a new perspective on how these programs run within a system and seeing how solutions were created so that we can run programs more efficiently. When making software I want to come back to this, knowing that one of these days’ problems such as deadlocking or shared variables will happen to me and so using the solutions Vaseekaran has listed in the post they wrote will help me a ton.
Link to “Concurrent Programming – Introduction”: https://gowthamy.medium.com/concurrent-programming-introduction-1b6eac31aa66