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 |
Tags
- Close
- json
- GO 언어
- http
- package
- window
- 영화
- FOR
- JavaScript
- tcp
- Sync
- Golang
- channel
- go
- windows
- File
- Python
- bitcoin
- Linux
- mutex
- C
- go언어
- range
- c++
- install
- Callback
- write
- API
- 책
- 리뷰
Archives
- Today
- Total
목록join (1)
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