Commit 18d1207
fix: add thread safety to brightness calculation
Added mutex lock to protect shared variables totalBrightness and
pixCount in isTooBright function. The imaging.AdjustFunc processes
pixels concurrently, which could cause race conditions when multiple
goroutines access and modify these shared variables simultaneously. This
ensures thread-safe calculation of average brightness when determining
if an image is too bright.
Influence:
1. Test image brightness detection with various image types and sizes
2. Verify that concurrent image processing does not cause race
conditions
3. Ensure brightness calculation remains accurate under multi-threaded
scenarios
4. Test with both bright and dark images to confirm proper functionality
fix: 为亮度计算添加线程安全保护
在 isTooBright 函数中添加互斥锁保护共享变量 totalBrightness 和
pixCount。由于 imaging.AdjustFunc 会并发处理像素,当多个 goroutine 同时
访问和修改这些共享变量时可能导致竞态条件。这确保了在确定图像是否过亮时,
平均亮度的计算是线程安全的。
Influence:
1. 测试各种图像类型和大小的亮度检测功能
2. 验证并发图像处理不会导致竞态条件
3. 确保在多线程场景下亮度计算保持准确
4. 使用亮图和暗图测试以确认功能正常1 parent 51d1a75 commit 18d1207
1 file changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | | - | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
0 commit comments