Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- range
- Golang
- package
- Linux
- JavaScript
- tcp
- 영화
- windows
- channel
- FOR
- json
- http
- go
- mutex
- window
- go언어
- 리뷰
- API
- File
- 책
- Sync
- write
- Callback
- GO 언어
- c++
- C
- bitcoin
- install
- Close
- Python
Archives
- Today
- Total
목록동기화 (2)
Code Habit
[c++] std::mutex를 사용하여 공유데이터 동기화 하기
여러 쓰레드에서 공유되는 데이터에 대해 동시에 접근하는 것을 방지하기 위해 std::mutex를 사용할 수 있다. #include #include int g_shared_data = 0; std::mutex g_mtx; void IncrementSharedData() { // 스코프 기반 락 관리 std::lock_guard lock(g_mtx); g_shared_data++; } int main() { std::vector threads; // 10개의 쓰레드 생성 및 실행 for(int i=0; i < 0; i++) { threads.emplace_back(IncrementSharedData); } // 모든 쓰레드가 종료될때까지 기다림 for(auto& thr : threads) { thr.join..
카테고리 없음
2024. 2. 3. 12:14
Go ) 원자적 연산
원자적 연산은 더 이상 쪼갤 수 없는 연산이라는 뜻이다. 따라서 여러 스레드(고루틴), CPU코어에서 같은 변수(메모리)를 수정할 때 서로 영향을 받지 않고 안전하게 연산할 수 있다. 보통 원자적 연산은 CPU의 명령어를 직접 사용하여 구현되어 있다. 사용 예제이다. package main import { "fmt" "runtime" "sync" "sync/atomic" } func main() { runtime.GOMAXPROCS(runtime.NumCPU()) // 모든 CPU 사용 var data int32 = 0 wg := new(sync.WaitGroup) for i:=0; i
카테고리 없음
2020. 6. 12. 07:57