LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-05-2000, 05:23 AM   #1
spachiap
LQ Newbie
 
Registered: Oct 2000
Posts: 1

Rep: Reputation: 0

Hi,

I am working on porting code to linux. The original code has
asm("cli") & asm("sti") inline assembly to disable
interrupts on a single processor system.

In linux, I found their equivalents to be
spin_lock_irq()/spin_unlock_irq(). The following program always gives a crash.
----------------------------------------------------------

#include <asm/spinlock.h>
#include <linux/smp_lock.h>
#include <asm/system.h>
#include <linux/linkage.h>

spinlock_t lock = SPIN_LOCK_UNLOCKED;
main()
{
func();

}

asmlinkage
int func()
{
unsigned long flags;

spin_lock_irqsave(&lock, flags);
/* critcal section */
spin_unlock_irqrestore(&lock, flags);
}

Please let me know why the program always crashes.
linux:20> ./a.out
Segmentation fault (core dumped)

Thanks,
Suresh

 
Old 11-23-2004, 06:41 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
spin_lock_irq is a kernel-space macro, and cannot be used from inside a user-space program (as far as I know).

A user-space program cannot disable hardware interrupts, as to do so would prevent any other programs or drivers from receiving any generated interrupts. Spinlocks do not context-shift, so they're only really useful on multi-processor systems when blocking for short periods of time; otherwise, you want to use a semaphore.

Also, you should probably be using spin_lock_irqsave rather than spin_lock_irq to save the interrupt state (see http://www.ussg.iu.edu/hypermail/lin...06.2/0310.html)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

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

All times are GMT -5. The time now is 10:38 AM.

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