title: Strange behavior of printk in linux kernel module
body: <p>I am writing a code for linux kernel module and experiencing a strange behavior in it. 
  Here is my code:</p>
  
  <pre><code>int data = 0;
  void threadfn1()
  {
      int j;
      for( j = 0; j &lt; 10; j++ )
          printk(KERN_INFO "I AM THREAD 1 %d\n",j);   
      data++;
  }
  
  void threadfn2()
  {
      int j;
      for( j = 0; j &lt; 10; j++ )
          printk(KERN_INFO "I AM THREAD 2 %d\n",j);
      data++; 
  }
  static int __init abc_init(void)
  {
          struct task_struct *t1 = kthread_run(threadfn1, NULL, "thread1");
          struct task_struct *t2 = kthread_run(threadfn2, NULL, "thread2");
          while( 1 )
          {
          printk("debug\n"); // runs ok
              if( data &gt;= 2 )
              {
                  kthread_stop(t1);
                  kthread_stop(t2);
                  break;
              }
          }
          printk(KERN_INFO "HELLO WORLD\n");
  
   }
  </code></pre>
  
  <p>Basically I was trying to wait for threads to finish and then print something after that.
  The above code does achieve that target but WITH <code>"printk("debug\n");"</code> not commented. As soon as I comment out <code>printk("debug\n");</code> to run the code without debugging and load the module through insmod command, the module hangs on and it seems like it gets lost in recursion. I dont why printk effects my code in such a big way?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>regards.</p>