20,741
edits
Philosopher (talk | contribs) No edit summary |
|||
| Line 59: | Line 59: | ||
My suggestion would be to add a global thread counter and increment/decrement it whenever you create/finish a thread – which will tell you what’s going on threading wise. | My suggestion would be to add a global thread counter and increment/decrement it whenever you create/finish a thread – which will tell you what’s going on threading wise. | ||
You could use something like this (crude and | You could use something like this (crude and just briefly tested): | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
var synced = {_LOCK:nil}; | var synced = {_LOCK:nil}; | ||
synced.new = func { | synced.new = func { | ||
| Line 72: | Line 71: | ||
var start = systime(); | var start = systime(); | ||
thread.lock( me._LOCK); | thread.lock( me._LOCK); | ||
if (thread_id) | if (thread_id != nil) | ||
print("Thread: ", thread_id, " spent waiting for lock:", systime()-start ); | print("Thread: ", thread_id, " spent waiting for lock:", systime()-start ); | ||
what(); | what(); | ||
thread.unlock( me._LOCK); | thread.unlock( me._LOCK); | ||
} | } | ||
var counter=synced.new(); | var counter=synced.new(); | ||
counter._value = 0; | counter._value = 0; | ||
counter.get = func return me._value; | counter.get = func return me._value; | ||
counter.atomic_do ( func counter. | var newthread = func(code, thread_id) { | ||
counter.atomic_do ( func counter._value +=1); # increment thread counter | |||
code(); # run callback in new thread | code(); # run callback in new thread | ||
counter.atomic_do ( func counter. | counter.atomic_do ( func counter._value -=1 ); # decrement thread counter | ||
} | |||
var stats = func { | |||
print("Threads:", counter.get() ); | |||
} | } | ||
print("***"); | |||
for(var i=0; i<15; i+=1) | |||
newthread( stats,i );</syntaxhighlight> | |||
</syntaxhighlight> | |||
You could also register a GC stats callback that dumps stats at the beginning/end of the thread, to see if objects/references roughly scale with the number of threads here. | You could also register a GC stats callback that dumps stats at the beginning/end of the thread, to see if objects/references roughly scale with the number of threads here. | ||
—[[User:Hooray|Hooray]] | —[[User:Hooray|Hooray]] | ||