단일 스레드 컴퓨팅 시스템에서는 한 번에 하나의 명령어가 입력되고 한 번에 하나의 결과가 출력됩니다. 프로그램을 로드하고 완료하는 데 걸리는 시간은 CPU가 수행해야 하는 작업량에 따라 다릅니다.
멀티스레딩은 여러 코어에서 한 번에 여러 개의 스레드를 처리하는 CPU 성능을 활용하는 프로그래밍의 한 유형입니다. 한 번에 하나가 아니라, 동시에 여러 개의 작업 또는 명령을 실행합니다.
어떤 스레드는 기본적으로 프로그램이 시작할 때 실행됩니다. 이 스레드가 바로 ’메인 스레드’입니다. 메인 스레드는 작업을 처리하기 위해 새로운 스레드를 생성합니다. 이러한 새 스레드는 다른 스레드와 병렬로 실행되며, 대개 실행이 완료되면 메인 스레드와 결과를 동기화합니다.
이러한 멀티스레딩 방식은 여러 개의 작업이 오랫동안 실행되는 경우에 적합합니다. 하지만 일반적으로 게임 개발 코드에는 한 번에 실행해야 할 작은 명령이 많이 들어 있습니다. 각 명령에 대해 스레드를 만들면 그 수가 너무 많아지고 각각의 수명도 짧아집니다. 따라서 CPU 및 운영체제의 프로세싱 능력을 초과할 수 있습니다.
스레드 풀을 사용하면 스레드 수명 주기 문제를 완화할 수 있습니다. 하지만 스레드 풀을 사용해도 동시에 활성화된 스레드 수가 너무 많을 수 있습니다. CPU 코어보다 스레드 수가 더 많으면 CPU 리소스를 놓고 스레드 간에 경쟁이 벌어지고, 이로 인해 컨텍스트 스위칭이 빈번하게 발생합니다. 컨텍스트 스위칭은 실행 도중에 스레드 상태를 저장하고 다른 스레드에 대한 작업을 진행한 후 첫 번째 스레드를 재구성하여 나중에 계속 처리하는 프로세스입니다. 컨텍스트 스위칭은 리소스를 매우 많이 소모하므로 가급적 사용하지 않는 것이 좋습니다.
2018–06–15 페이지 게시됨
2018.1에서 공개된 C# 잡 시스템 NewIn20181
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.