lots of improvements for pfor

TODO:
- void * casting and down-casting
- initialize temp global vars in thread functions to their corresponding
global vars initial values