roxen.lists.pike.general

Subject Author Date
thread and lambda zenothing <zenothing[at]hotmail[dot]com> 22-03-2009
Pike accept any function as a thread start point.

I'm thinking that if we can request the programer to declare the thread-shared
variables clearly, we can help them to avoid forgetting a mutex lock.

for example:

Thread.Thread(lambda()); //good, no thread-shared variables at
all


string s="haha";
Thread.Thread(lambda(){write( s );}); //bad, the programmer may not notice the
var s is shared by threads, so he forget to lock it.

Class T{
string s="haha"
void mythreadmain()
{
    write( s );
}
}
Thread.Thread(T()->mythreadmain); //good, the programmer should have clearly
known whether s is shared by threads.




My suggestion is: don't allow lambda function that references the non-local
variables but not class property variables as a thread start point.



Guo Xuesong