Implement AUTO_FREE flag for thread_create

Currently the `AUTO_FREE` flag (defined in flags.h) is unused.

Implementing it will be helpful for dynamic thread creation (e.g. by pthreads).