Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
OpenRA/OpenRA 111052 BAD_LOCK_OBJECT Unreliable locking behavior We didn't figure ourselves where those threading issues came from and tried to hide them with hacks. https://github.com/OpenRA/OpenRA/pull/3727 Now it can finally be properly fixed.
File: /OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
                        mixerSprite = new Sprite(mixerSheet, rect, TextureChannel.Alpha);
                }

                void GenerateBitmap()
                {
                        // Generating the selection bitmap is slow,
                        // so we do it in a background thread
                        lock (syncWorker)
                        {
                                update = true;

                                if (workerThread == null || !workerAlive)
                                {
                                        workerThread = new Thread(GenerateBitmapWorker);
                                        workerThread.Start();
                                }
                        }
                }

                void GenerateBitmapWorker()
                {
                        lock (syncWorker)
                                workerAlive = true;

 < 1. Condition "true", taking true branch
83
                        for (;;)
 < 1. Condition "true", taking true branch
84
85
86
87
                        {
                                float hue;
                                lock (syncWorker)
                                {
 < 2. Condition "!this.update", taking false branch
88
                                        if (!update)
 < 2. Condition "!this.update", taking false branch
89
90
91
92
93
94
95
96
97
98
99
                                        {
                                                workerAlive = false;
                                                break;
                                        }

                                        update = false;

                                        // Take a local copy of the hue to generate to avoid tearing
                                        hue = H;
                                }

 << 3. Acquiring lock "ColorMixerWidget.back".
100
                                lock (back)
 << 3. Acquiring lock "ColorMixerWidget.back".
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                                {
                                        unsafe
                                        {
                                                // Generate palette in HSV
                                                fixed (byte* cc = &back[0])
                                                {
                                                        var c = (int*)cc;
                                                        for (var v = 0; v < 256; v++)
                                                                for (var s = 0; s < 256; s++)
                                                                        *(c + (v * 256) + s) = HSLColor.FromHSV(hue, s / 255f, (255 - v) / 255f).RGB.ToArgb();
                                                }
                                        }

                                        lock (front)
                                        {
                                                var swap = front;
                                                front = back;
                                                back = swap;
                                        }
                                }
                        }
                }

                public override void Draw()
                {
                        if (Monitor.TryEnter(front))
                        {
Events:
3. lock_acquire ColorMixerWidget.cs:100
3. lock_acquire ColorMixerWidget.cs:100
3. lock_acquire ColorMixerWidget.cs:100
3. lock_acquire ColorMixerWidget.cs:101
3. lock_acquire ColorMixerWidget.cs:101
3. lock_acquire ColorMixerWidget.cs:101