kthread: Add kthread_start()

In the current API, there is a small time window that kthread_stop()
will skip the ->threadfn() and return -EINTR even if wake_up_process()
is called previously:

	CPU 0			CPU 1
	=====			=====
	t = kthread_create(...);
				<in the new thread t>
				kthread():
				  ...
				  complete(done);
				  schedule_preempt_disabled();
	wake_up_process(t);
				  preempt_enabled();
	kthread_stop(t);
	  ...
	  set_bit(KTHREAD_SHOULD_STOP, ...):
				  ...
				  ret = -EINTR;
				  if (!test_bit(KTHREAD_SHOULD_STOP, ..)) {
				    ...
				  } // <- if is false, skip the threadfn()

				  kthread_exit(ret);

In other words, kthread API doesn't guarantee the threadfn() will be
executed even after wake_up_process(), users have to provide their own
synchronization to verify it.

TODO

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
2 files changed