added one step of indirection to thread_data for thread locking scheme which made the rest of the code simpler again, removed local_free()