void *main = osnoise_main;
        char comm[24];
 
+       /* Do not start a new thread if it is already running */
+       if (per_cpu(per_cpu_osnoise_var, cpu).kthread)
+               return 0;
+
        if (timerlat_enabled()) {
                snprintf(comm, 24, "timerlat/%d", cpu);
                main = timerlat_main;
                if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask)) {
                        struct task_struct *kthread;
 
-                       kthread = per_cpu(per_cpu_osnoise_var, cpu).kthread;
+                       kthread = xchg_relaxed(&(per_cpu(per_cpu_osnoise_var, cpu).kthread), NULL);
                        if (!WARN_ON(!kthread))
                                kthread_stop(kthread);
                }
-               per_cpu(per_cpu_osnoise_var, cpu).kthread = NULL;
        }
 
        for_each_cpu(cpu, current_mask) {