LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2003, 01:02 AM   #1
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
how does while(1) lock the CPU?


I am in the midst of an interesting discussion...
how while( 1 ) locks the CPU,
i am of the opinion that since it is executing in too tight a loop to allow cpu to send an interrupt to remove the process from run queue....

my friend does not seem totally convinced....please see if anyone has some explanation or pointers in this matter...

thanks
 
Old 09-19-2003, 01:41 AM   #2
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
you wont necessarily lock the CPU, but you can lock up your program if that isnt running as a seperate thread. The CPU itself wont spend all of its time in 1 program no matter what that one program is doing.
 
Old 09-19-2003, 01:58 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Original Poster
Rep: Reputation: 33
yeah that was actually my understanding also...but i was having some doubts...i was trying to corelate this with the spin locks....
which also execute a very tight loop (atomically (and hence, similar to while(1)));

am i right in this comparison?
 
Old 09-20-2003, 02:42 PM   #4
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
i dont. what is a spin lock?
 
Old 09-21-2003, 05:29 AM   #5
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Original Poster
Rep: Reputation: 33
ill be talking about kernel threads when i say threads in this post

the spin locks are a synchronization method in kernel..
mainly used in SMP (multi processing environments)...

these locks are test and set locks in which if one thread, 'thread1' has the lock, and some other thread wants to acquire the lock, the second thread keeps testing the lock by 'spinnin' around it, that is, testing whether the lock has been freed by the by in a very tight loop, this is all atomically done, and this code has the potential to lock the CPU, if executed in a UP (uniprocessor ) environment,


something like this code :
spinlock
{
while(1)
{
if (lock not set)
spin_lock();
}
}


heres how the CPU might get locked in the UP enviroment, when using spin locks,
suppose thread one has the lock and is about to execute its critical section, at that very moment , a thread with higher priority tries to obtain the lock and starts 'spinning', now since this is the higher priority thread, the first thread never gets a chance to execute the critical section, and thus, cant free the lock, thus, causin the cpu to lock, as the higher priority thread always keeps spinning around that lock.

this is where i saw a similarity between while 1 and the spin locks...

btw, i think certain workarounds exist to make spin locks work on UP systems, like specifying the spin time, ifa thread does not get a lock in certain amount of time, it is removed from the run queue,
 
Old 09-21-2003, 03:05 PM   #6
mhearn
LQ Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
Erm, was your original post about kernel programming too? If so you should really say so - spinlocks are not used in user mode programming except implicitly via other locking primitives....
 
Old 09-22-2003, 12:06 AM   #7
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Original Poster
Rep: Reputation: 33
umm, i am not talking about user land or kernel land, i am just trying to draw a parallel between a spin lock and a while (1)(not fully but to a certain extent.. )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable) phreakshew Linux - Newbie 24 04-12-2019 10:42 AM
Caps Lock and Num Lock leds dont work! npc Linux - Hardware 2 11-08-2005 10:40 AM
BUG: soft lock detected on CPU#0 nibbler Linux - Newbie 1 08-22-2005 02:14 PM
Num, Scroll, Caps/Lock all Lock up Slackware Zamochit Linux - Newbie 0 10-18-2004 07:47 PM
RedHat 9.0 freezes with blinking Caps lock and Scroll lock queen-bee Linux - Software 0 07-30-2004 10:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration