-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken object modification in thread.
- Loading branch information
1 parent
e8835ba
commit 5fad5de
Showing
10 changed files
with
103 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import thread | ||
|
||
var start = time() | ||
|
||
var N = 21 | ||
|
||
def make_tree(depth) { | ||
if depth <= 0 return [nil, nil] | ||
depth -= 1 | ||
return [make_tree(depth), make_tree(depth)] | ||
} | ||
|
||
def check_tree(node) { | ||
var left = node[0], right = node[1] | ||
if !left return 1 | ||
return 1 + check_tree(left) + check_tree(right) | ||
} | ||
|
||
var min_depth = 4 | ||
var max_depth = max(min_depth + 2, N) | ||
var stretch_depth = max_depth + 1 | ||
|
||
echo 'stretch tree of depth ${stretch_depth}\t check: ${check_tree(make_tree(stretch_depth))}' | ||
|
||
var long_lived_tree = make_tree(max_depth) | ||
|
||
var iterations = 2 ** max_depth | ||
|
||
var thrds = [] | ||
var lines = [] | ||
iter var depth = min_depth; depth < stretch_depth; depth += 2 { | ||
lines.append(nil) | ||
|
||
thrds.append(thread.start(@(_, lines, i, iterations, depth){ | ||
var check = 0 | ||
for i in 1..(iterations + 1) { | ||
check += check_tree(make_tree(depth)) | ||
} | ||
|
||
lines[i] = '${iterations}\t trees of depth ${depth}\t check: ${check}' | ||
}, [lines, lines.length() - 1, iterations, depth])) | ||
|
||
iterations //= 4 | ||
} | ||
|
||
iter var i = 0; i < thrds.length(); i++ { | ||
thrds[i].await() | ||
echo lines[i] | ||
} | ||
|
||
echo 'long lived tree of depth ${max_depth}\t check: ${check_tree(long_lived_tree)}' | ||
echo 'Total time taken: ${time() - start}' |
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -82,6 +82,7 @@ struct s_vm { | |
|
||
// id | ||
uint64_t id; | ||
b_vm *parent_vm; | ||
}; | ||
|
||
void init_vm(b_vm *vm); | ||
|