race condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
   I am trying to trace the race condition by creating 2 threads in
kernel space.   One thread incriments a global value and other
decrements that value.
But I am unable to trace the race condition.
I am listing my code.Will you please help me.
thanks in advance

#ifndef __KERNEL__
	#define __KERNEL__
#endif

#ifndef MODULE
	#define MODULE
#endif

#include <linux/kernel.h> 
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <asm/atomic.h>
#include <asm/processor.h>

MODULE_AUTHOR("RAJA");
MODULE_DESCRIPTION("ATOMIC 1");
MODULE_LICENSE("GPL");

static int __init init_module_atomic(void);
static void __exit exit_module_atomic(void);

int value=0;

int thread_function_1(void * data)
{
	printk("Entered into Thread 1\n");
	int i;
	for(i=0;i<1000;i++)
	{
		udelay(1000);
		value++;
		printk("Value Is : %d\t",value);
	}
	printk("Exited From Thread 1\n");
	return 0;
}

int thread_function_2(void * data)
{
	printk("Entered into Thread 2\n");
	int i;
	for(i=0;i<1000;i++)
	{
		udelay(100);
		value--;
		printk("Value Is : %d\t",value);
	}
	printk("Exited From Thread 2\n");
	return 0;
}

static int __init init_module_atomic()
{
	printk("Entered Into init function\n");
	pid_t thread1;
	pid_t thread2;
	thread1 = kernel_thread(thread_function_1,NULL,0);
	thread2 = kernel_thread(thread_function_2,NULL,0);
	printk("Exited From init function\n");
	return 0;
}

static void __exit exit_module_atomic()
{
	printk("Entered Into exit function\n");
	printk("Returned From exit function\n");
}

module_init(init_module_atomic);
module_exit(exit_module_atomic);




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux