Commit 38c7783
chatgris
Fix a potential threadsafe issue
Lazily setting @Mutex could lead to have two mutexes with a sample code
like:
[MyListener.new, MailListener.new].each do |listener|
Thread.new {
Wisper::GlobalListeners.add_listener(listener)
}
end
This example is cumbersome, but well, it shows the idea. Even with a
singleton, if `add_listener` is called a first time by two different
threads, this could lead to thread safety issues for ruby implementation
without a gvl.
Signed-off-by: chatgris <jboyer@af83.com>1 parent ea21c55 commit 38c7783
1 file changed
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 41 | | |
43 | 42 | | |
44 | 43 | | |
| |||
0 commit comments