Created
August 16, 2010 15:48
-
-
Save fredreichbier/527163 to your computer and use it in GitHub Desktop.
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
import threading/Thread | |
local := ThreadLocal<Pointer> new() | |
setCell: func { | |
cell := Cell<Int> new(123) | |
"cell is %p" format(cell) println() | |
local set(cell) | |
} | |
testWithoutMalloc: func { | |
"without malloc:" println() | |
setCell() | |
value := local get() | |
"cell is now %p" format(value) println() | |
} | |
testWithMalloc: func { | |
"with malloc:" println() | |
setCell() | |
gc_malloc(1) | |
value := local get() | |
"cell is now %p" format(value) println() | |
} | |
main: func { | |
testWithoutMalloc() | |
testWithMalloc() | |
testWithoutMalloc() | |
testWithMalloc() | |
} |
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
without malloc: | |
cell is 0x84b9fd0 | |
cell is now 0x84b9fd0 | |
with malloc: | |
cell is 0x84b9fc0 | |
cell is now 0x9 | |
without malloc: | |
cell is 0x84b9fb0 | |
cell is now 0x84b9fb0 | |
with malloc: | |
cell is 0x84b9fa0 | |
cell is now 0x13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment