일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- ASW(Application SpaceWarp)
- Rim Light
- C언어
- working set
- 가상 바이트
- OculusMotionVectorPass
- Specular
- 게임 수학
- Private Bytes
- VR
- URP
- Cell Shader
- Cartoon Rendering
- Cell Look
- Windows Build
- 벡터
- 작업 집합
- 개인 바이트
- URP로 변경
- Three(Two) Tone Shading
- 3d
- 프로그래밍 기초
- 메모리 누수
- Virtual Byte
- AppSW
- ColorGradingLutPass
- Toon Shader
- Today
- Total
WinCNT
TLS(Thread Local Storage) 본문
참고 사이트
_beginthread, _beginthreadex
자세한 정보: _beginthread, _beginthreadex
docs.microsoft.com
https://docs.microsoft.com/ko-kr/cpp/parallel/concrt/concurrency-runtime?view=msvc-170
동시성 런타임
자세한 정보: 동시성 런타임
docs.microsoft.com
동시성 런라임에서 PPL(병렬 패턴 라이브러리)를 특히 추천!
다만 동시성 런타임을 사용하기 위해서는 Modern C++를 배울 필요가 있음
1. L-Value, R-Value, 이동 생성자, std::move
2. 함수 객체(Functor), 람다식
3. 서버인 경우에는 conccurency
4. std::mutex - 서버용 OS에서 매우 빠르다고 한다(?)
물론 잘 알고 사용해야 한다
예를 들어 concurrent_queue의 경우에도 동시성 안전인 함수가 있고 아닌 함수가 있다
std::thread
필요한 헤더 파일
#include <functional> //std::function
using namespace std;
#include <thread>
#include <concurrent_queue.h>
using namespace Concurrency;
Callback Function?
함수 객체(Function Object)는 함수처럼 동작하는 객체
객체가 함수처럼 동작하도록 () 연산자를 재정의
TLS(Thread Local Storage)
한 쓰레드 내에서 전역 변수나 정적 변수처럼 쓸 수 있지만,
같은 프로세스라도 다른 쓰레드에서는 접근이 불가능한 저장 영역
(실제로 스레드 각각의 전역 변수의 주소값이 다르다)
/// <summary>
/// TLS(Thread Local Storage)
/// Thread마다 별도의 공간을 할당받는다
/// </summary>
__declspec(thread) int g_tlsCount = 0;
int main()
{
//...
}
Thread Local Storage (TLS)
Learn more about: Thread Local Storage (TLS)
docs.microsoft.com
TlsAlloc 함수를 사용한 TLS 인덱스를 할당
https://docs.microsoft.com/ko-KR/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc
TlsAlloc function (processthreadsapi.h) - Win32 apps
Allocates a thread local storage (TLS) index. Any thread of the process can subsequently use this index to store and retrieve values that are local to the thread, because each thread receives its own slot for the index.
docs.microsoft.com
전역 변수는 프로그램이 실행될 때 할당되어야 하므로
DllMain에서 DLL_PROCESS_ATTACH 될 때 TlsAlloc()으로 먼저 할당해주자
SSS
'게임 프로그래밍(학습 내용 정리) > 시스템 프로그래밍' 카테고리의 다른 글
Dynamic-Link Library(DLL) - 추가 사항 (0) | 2022.06.07 |
---|---|
Dynamic-Link Library(DLL) - 명시적 링킹(Explicit Linking) (0) | 2022.06.07 |
Dynamic-Link Library(DLL) (0) | 2022.05.23 |
어플리케이션에서 가상 메모리 사용 방법 (0) | 2022.05.23 |
작업 집합(Working Set), 가상 바이트(Virtual Byte), 개인 바이트(Private Bytes)...그리고 메모리 누수 (0) | 2022.05.16 |