기본 콘텐츠로 건너뛰기

추천 게시물

[Go] 고루틴

런타임(Runtime) visual code에서 브라우저 실행 단축키: Alt+B Go runtime은 메모리 관리, 가비지 수집, 동시성을 포함하여 Go 프로그림의 실행을 관리하는 역할을 합니다. 이 문서에서는 Go runtime을 자세히 살펴보고 아키텍초, 특성과 장점을 살펴봅니다. Go Runtime Architecture Go runtime은 모듈식이고 유연하게 설계되었으며 개발자가 특정 요구사항에 따라 동작을 사용자 정의할 수 있는 계층적 아키텍쳐를 갖추고 있습니다. 런타임은 스케줄러(schedualer), 가비지 수집기(garbage collector), 메모리 할당자(memory alllocator) 및 스택관리(stack management)를 포함한 어려 핵심 구성 요소로 구성됩니다. Schedualer Go 런타임의 핵심은 고루틴의 실행을 관리하는 스케줄러입니다. 고루틴은 효율적인 동시성을 가능하게 하는 가벼운 스레드입니다. 스케줄러는 사용 가능한 스레드에 고루틴을 분산하고, 스레드 로컬 스토리지를 관리하고, I/O 작업을 조정하는 역할을 합니다. thread(스레드): 프로그램 내에서 실행되는 흐름의 단위로 동시에 여러 작업이나 프로그램을 실행하는 것입니다. 즉, 코드를 실행할 수 있는 각 단위를 스레드라고 합니다. 고루틴(goroutine): Go 언어로 동시에 실행되는 모든 활동을 의미합니다. 고루틴을 만드는 비용을 스레드에 비해 매우 적기 떄문에 경량 스레드라고 합니다. 모든 프로그램은 적어도 하나의 main() 함수라는 고루틴을 포함하고 고루틴은 항상 백그라운드에서 작동합니다. 메인함수가 종료되면 모든 고루틴은 종료됩니다. 그러므로 고루틴보다 main이 먼저 종료되는 것을 방지해야 합니다. Go 스케줄러는 매우 효율적이고 확장 가능하도록 설계되어 많은 수의 동시 고루틴을 손쉽게 처리할 수 있습니다. 스레드 간에 부하를 분산하여 경합을 최소화하고 성능을 개선하는 작업 훔치기 알고리즘을 사용합니다...

reference_Python

Computer memory stores all input parts, either numbers or letters, as binary numbers, that is, 0 and 1. This stored data is recognized by Python as an object.
In Python, objects are classified based on the following data types:
Integer type, real type, character type, string type, list type, tuple type, dictionary type
Of these, string, list, tuple, and dictionary are data types and data structures. In other words, this structure contains basic data types such as int, float, and character inside it, and is treated as a data type.
id () returns a reference to an object. Use this function to:

In [1]: [1,2,3]
Out[1]: [1, 2, 3]

In [2]: y=[1,2,3]
In [3]: [id([1,2,3]),id(y)]
Out[3]: [2465266218760, 2465266012296]

Code [2] stores the list object created in code [1] in another object, y. According to the result of code [3], object names y and [1,2,3] are not in the same space. In other wise, object y refers to object [1,2,3] of code [1].
The list of code [1] also refers to each element in its structure. This reference address is the same as the reference address of each element of object y (code [6])

In [4]: [id(1),id(2),id(3)]
Out[4]: [1700837840, 1700837872, 1700837904]

In [5]: [id(y[0]),id(y[1]),id(y[2])]
Out[5]: [1700837840, 1700837872, 1700837904]

In [6]: [id(1),id(2),id(3)]==[id(y[0]),id(y[1]),id(y[2])]
Out[6]: True


In the figure above, the objects created in memory are each number, that is, element type, and these numbers can be combined to create lists and dictionary formats.
The important thing here is that the object y also refers to the list object [1,2,3], but the reference to each element refers to the source part referenced by the list object of [1,2,3].
So what happens if you modify the element value of an object in y? (List objects can modify elements.)

In [7]: y[2]='a'
In [8]: y
Out[8]: [1, 2, 'a']

In [9]: [id([1,2,3]),id([1, 2, 'a']), id(y)]
Out[9]: [2465216865032, 2465216865032, 2465266012296]

The results of the codes [7] - [9] are interesting. When an element of object y was changed, the reference address of y is not changed and the reference address of the referenced object is changed.

In [10]: [id(1),id(2),id('a')]
Out[10]: [1700837840, 1700837872, 2465036771992]

In [11]: [id(y[0]),id(y[1]),id(y[2])]
Out[11]: [1700837840, 1700837872, 2465036771992]

An object of [1,2, 'a'] created from the results of the codes [10] and [11] is the reference 1 and 2 in the code [1] and the reference value is changed to the third element 'a' .
However, the reference address of the object y means that there is no change before and after the modification of the element, which means that [1,2, 'a'] is changed in place of [1,2,3].


In short
1. The data construction on the computer is based on the binary method 0 and 1. Based on this, all input data is converted to 0 and 1 and stored. Complex data structures such as strings, lists, tuples, and dictionaries are generated by combining the basic data types (integer, real, and character) generated.
2. Generate more complex data such as lists.
3. An object created with a separate name refers to the data generated in Step 2 for its contents.


댓글