This paper describes a generic mechanism to migrate threads in heterogeneous distributed environments. To maintain high portability and flexibility, thread migration is implemented at language level. At compile-time, a preprocessor scans the C and C++ programs to build thread state, detects possible thread migration points, and transforms the source code accordingly. Run-time support helps migrate threads physically. Since the physical thread state is transformed into a logical form, and pointers and dynamically allocated memory in heap are supported, the proposed solution places no restriction on thread types and migrationenabled systems. We implemented this approach in Strings: a multithreaded software distributed shared memory system. Some microbenchmarks and performance measurements on SPLASH-2 suite are reported.