Threads and Concurrency

248 단어·2 분·원문(.md)

Thread #

  • Refers to a unit of execution flow within a program, specifically within a process.
  • Generally, a program has a single thread, but depending on the program environment, it can execute two or more threads concurrently. This execution method is called multithreading.

Multithreading #

Multithreading refers to the execution of two or more threads concurrently within a single process. In multithreading, each thread shares the memory of the process it belongs to.


Concurrency and Parallelism in Multithreading #

Concurrency is a method for running multiple threads on a single core, referring to the characteristic where multiple threads are executed alternately for multitasking. Multitasking on a single core using concurrency makes it appear as if each thread is running in parallel, but in reality, they are executing in turns, little by little.

Parallelism is a method for running multiple threads on multiple cores, referring to the characteristic where each core, containing one or more threads, executes simultaneously. Parallelism is divided into data parallelism and task parallelism.

Data Parallelism This refers to splitting the entire data into sub-data sets, then processing these sub-data sets in parallel to perform tasks quickly. Java 8's parallel streams implement data parallelism. Sub-data sets are split according to the number of multi-cores, and each data set is processed in parallel on separate threads.

Task Parallelism This refers to processing different tasks in parallel. A prime example is a web server, which processes requests from different browsers in parallel on individual threads.

정보처리/스레드.md