Files
nexus/wiki/concepts/并发编程.md
2026-04-22 12:02:55 +08:00

37 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "并发编程"
type: concept
tags: [software-engineering, concurrency, multi-threading, async]
sources: [开发经验与项目规范整理文档]
last_updated: 2025-12-30
---
## Definition
**并发编程** 是指程序中多个执行流同时存在的编程范式,需要处理共享资源、数据竞争、锁机制等问题。
## Core Principles
- 清晰区分共享资源
- 避免数据竞争Race Condition
- 必要时加锁或使用线程安全结构
- 区分「并发处理」和「异步处理」的差异
## Concurrency vs Async
| 维度 | 并发Concurrency | 异步Async |
|------|---------------------|--------------|
| 目标 | 同时执行多个任务 | 不阻塞等待 I/O |
| 实现 | 多线程、多进程 | 事件循环、回调、Promise |
| 问题 | 数据竞争、死锁 | 回调地狱、状态管理 |
## Related Concepts
- [[单一职责原则]] — 线程安全的函数应保持单一职责
- [[输入-处理-输出模型]] — 并发环境下的数据流管理
- [[消息队列]] — 替代直接共享资源的并发安全方案
## Source Reference
来源:[[开发经验与项目规范整理文档]]