Re: spin locks

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

 



On 9/22/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
> Hi,
>    I am writing a module to test the spin locks.In that i am creating 2
> threads.In that 2 threads i am taking a value and incrimenting upto some
> value and printing.
> But with out using spin lock the code is properly working.(i.e)the first
> thread is executed for some time and after that the 2nd thread preempts
> the first and it is also executing for some time.
>

You need to have CONFIG_PREEMPT enabled or use a SMP system, if you
really wants to check spin_lock as on a single CPU system you won't be
able to get the race condition until you enable preemeption in the
kernel ...........

> but if i use spinlock and printing part i locked.
> Here actually after the thread1 teriminated then only the 2nd thread has
> to execute.But it is not happening.Simply the system hangs.
>
> I am listing the code below.
>

Your approach is wrong ..... First you are scheduling with-in
spin_lock acquired which won't have to be done .......... Second you
are using local variables in threads so no race condition and you are
also testing on UP system, so won't be able to get your desired
results ....


--
Fawad Lateef

--
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