-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow pattern inside static block, add low confidence label
- Loading branch information
1 parent
0ad895c
commit 1389af1
Showing
3 changed files
with
38 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
using Base.Threads | ||
using Base.Threads: threadid, @threads | ||
|
||
states = zeros(10) | ||
Threads.@spawn for i = 1:10 | ||
Threads.@threads for i = 1:10 | ||
# ruleid: index-by-threadid | ||
tid = Threads.threadid() | ||
old_val = states[tid] | ||
new_val = old_val + i | ||
states[tid] = new_val | ||
end | ||
|
||
@spawn begin | ||
@threads for i = 1:10 | ||
# ruleid: index-by-threadid | ||
tid = threadid() | ||
val = states[tid] | ||
states[tid] = val + 1 | ||
end | ||
|
||
Threads.@spawn for i = 1:10 | ||
@threads :foo for i = 1:10 | ||
# ruleid: index-by-threadid | ||
val = states[threadid()] | ||
val = states[Threads.threadid()] | ||
end | ||
|
||
|
||
Threads.@spawn for i = 1:10 | ||
# ruleid: index-by-threadid | ||
Threads.@threads :static for i = 1:10 | ||
# ok: index-by-threadid | ||
val = states[Threads.threadid()] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
rules: | ||
- id: index-by-threadid | ||
patterns: | ||
- pattern-inside: | | ||
@threads ... for $X = ... | ||
... | ||
end | ||
- pattern-not-inside: | | ||
@threads :static for $X = ... | ||
... | ||
end | ||
- pattern-either: | ||
- pattern: $S[Threads.threadid()] | ||
- pattern: $S[threadid()] | ||
- pattern: | | ||
$TID = Threads.threadid() | ||
... | ||
$Y = $S[$TID] | ||
- pattern: | | ||
$TID = threadid() | ||
... | ||
$Y = $S[$TID] | ||
message: Indexing by `threadid()` may cause race conditions and should be avoided. | ||
metadata: | ||
confidence: LOW | ||
references: | ||
- https://www.julialang.org/blog/2023/07/PSA-dont-use-threadid/ | ||
license: LGPL | ||
languages: | ||
- julia | ||
severity: WARNING |
This file was deleted.
Oops, something went wrong.