Skip to content

Instantly share code, notes, and snippets.

@fredreichbier
Created August 16, 2010 15:48
Show Gist options
  • Save fredreichbier/527163 to your computer and use it in GitHub Desktop.
Save fredreichbier/527163 to your computer and use it in GitHub Desktop.
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()
}
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