Solved

How to invoke Spin Locks methods or macros in Red Hat Linux?

Posted on 2004-09-10
8
333 Views
Last Modified: 2010-08-05
Hi,

I need to implement some section of code in Linux that I must use Spin Locks. My box is Red Hat AS Enterprise 3.0.

If you've known about the Spin Locks in Red Hat Linux: how to use them, how to invoke their library functions or system calls, please give some help.

Thanks a lot,

Rfr1tz

0
Comment
Question by:rfr1tz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12033351
Hi Rfr1tz,

Spinlocks are available inside the kernel but I do not think they are provided in the user library ... What are you trying to accomplish? Won't smeaphores and/or conditional variables of some help?

sunnycoder
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 12037349
hi,
  If you are In user space you need spinlocks if you are writing multithreaded apps.
 So you might be using pthreads. Pthreads have a righ locking mechanisms including mutex, condvars, barriers, semaphores etc.

I think pthread mutex is what you are looking for.
int   pthread_mutex_lock(pthread_mutex_t *);
int   pthread_mutex_unlock(pthread_mutex_t *);

http://www.opengroup.org/onlinepubs/007908799/xsh/pthread.h.html

google for a tut on pthreads.
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
 
regards manish
 
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12041295
Hi Manish,

I would not recommend using pthreads just for using their locking mechanisms. A lot of things can go wrong with an application which uses threads while there is no need. :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:rfr1tz
ID: 12044795
Hi sunnycoder and manish_regmi,

Our system is SMP (symmetric multiple processors). And The assignment requires that we must implement spin locks so that it would be polled coninuously to eb able to get the lock in the shortest period of time in some special cases whre the waiting time is very short.
 
I read into some articles of internets and found that some functions of spin locks are amentioned like:
-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

...

I don't know whether we can called these functions at user levels or not? If you alrready have experiences with these, please help.
I also looked into /usr/include/asm/spinlocks.h

I found the file there but the file is empty. Do you have any idea why the file is empty? And also, if I'd liek to look into the file spinlock.c. Do you know where this file is, which directory the file resides?

Thanks a lot,

Rfr1tz

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 12051582
Look for

documentation/spinlocks.txt  ... It will give information about the spinlocks in your kernel.

-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

These are available at kernel level only. An names suggest, they are used for interrupt request handling
0
 
LVL 8

Assisted Solution

by:manish_regmi
manish_regmi earned 125 total points
ID: 12051590
hi,
 Spinlocks in SMP are more difficult to implement. You cannot just implement traditional test_and_set() mechanism. I have never used spinlocks in user space. The function you gave is for kernel.
 I think it will be better you copy linux spinlock code from linux kernel tree (and remember include those with #ifdef CONFIG_SMP). And there are a lot of things you need to omit.

http://lxr.linux.no/source/include/linux/spinlock.h
http://lxr.linux.no/source/include/asm-i386/spinlock.h

CAn you extract what you require?

regards manish
 
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question