20,741
edits
Philosopher (talk | contribs) No edit summary |
m (→August 14) |
||
| Line 51: | Line 51: | ||
<hr/> | <hr/> | ||
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 untested untested): | |||
<syntaxhighlight lang="php"> | |||
var synced = {_LOCK:nil}; | |||
synced.new = func { | |||
var temp = { parents:[synced] }; | |||
temp._LOCK = thread.newlock(); | |||
} | |||
synced.do = func (what, thread_id=nil) { | |||
var start = systime(); | |||
thread.lock( me._LOCK); | |||
if (thread_id) | |||
print("Thread: ", thread_id, " spent waiting for lock:", systime()-start ); | |||
what(); | |||
thread.unlock( me._LOCK); | |||
} | |||
var counter=synced.new(); | |||
counter._value = 0; | |||
counter.get = func return me._value; | |||
thread.newthread = func(code, thread_id) { | |||
counter.do ( counter.get() +=1 ); | |||
code(); | |||
counter.do (counter.get() -=1 ); | |||
} | |||
var stats = func print("Threads:", counter.get() ); | |||
forindex(var i; 15) | |||
thread.newthread( stats,i ); | |||
</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]] | ||