Added generic thread API + some example code.