-
Notifications
You must be signed in to change notification settings - Fork 0
Make ResourcePackageReader thread-safe using FileShare.Read #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ResourcePackageReader thread-safe using FileShare.Read #18
Conversation
Co-authored-by: Soar360 <[email protected]>
Co-authored-by: Soar360 <[email protected]>
|
我有几个小问题
|
Co-authored-by: Soar360 <[email protected]>
优秀的观察!你完全正确。我已经按照你的建议优化了实现: 回答你的问题:
变更(commit 62be3a1):
所有 36 个测试通过。这是更优的线程安全实现。 |
|
@copilot 你做的很好,还需要解决以下问题: 1、从现在看,ResourcePackageReader 已经没有必要实现 IDispose 接口了。 |
Co-authored-by: Soar360 <[email protected]>
完成!两个问题都已解决(commit f7d1483): 1. 移除 IDisposable 接口
2. 重新设计 GetStream() 支持真正的流式处理
优势:
所有 32 个测试通过。 |
The source generator creates static
ResourcePackageReaderinstances shared across threads. Without synchronization, concurrent reads corrupt data as FileStream Seek/Read operations interleave.Changes
ResourcePackageReader: Optimized for true concurrent reads using FileShare.Read
ReadResourceAsync(),ReadResource(): Create independent FileStream per operation with FileShare.ReadGetStream(): ReturnsResourceSubStreamfor true streaming without loading data into memoryResourceSubStream: New internal class for streaming large resources
Thread-safety tests: 7 tests validating concurrent access patterns (async/sync reads, streams, mixed operations)
Performance Benefits
GetStream()supports streaming large resources without loading into memoryExample
Generated static accessor now safe for concurrent use:
Each read operation creates its own FileStream with
FileShare.Read, allowing the OS to handle concurrent file access efficiently without application-level locking.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.