LinuxQuestions.org
Visit Jeremy's Blog.
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 05-23-2012, 05:59 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
What is a reentrant code with respect to thread safety?


What I have understood by now:

Quote:
A code is considered reentrant if the process/thread executing it can be interrupted in the middle of its execution and then safely be resumed again. The interruption could be caused by an internal action such as a `goto` statement, by an external action such as process scheduling by the kernel, or by a hardware interrupt. Also, a code which can be accessed by the multiple threads at the same time without any kind of curruption in the shared data structures is called reentrant code.
.
Making a code reentrant requires the saving of state information in variables local to each execution, usually on a stack, rather than in a static variable, global variables, or other non-local state.
Is this understanding completely correct?
 
Old 05-23-2012, 06:12 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Anisha Kaul View Post
What I have understood by now:



Is this understanding completely correct?
I think that "process scheduling by the kernel, or by a hardware interrupt" is not very clearly put.

If a user program runs at the moment, and if we have just one core, kernel does not run at the same time. I.e. simply no other program runs at the time.

I.e. switching to kernel will be caused by an external interrupt anyway - if nothing else happens, it will be interrupt from timer.

Or, to put it differently, external interrupts are hidden from user by kernel. Unless one decides to implement something really sophisticated in which there are HW interrupts with ISRs (Interrupt Service Routines) implemented outside the kernel.

...

I hope I've sufficiently confused you .
 
  


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
How to enter code into thread? hilltownboy LQ Suggestions & Feedback 5 05-09-2011 01:51 AM
python thread safety: printing from thread to redirected stdout - safe? BrianK Programming 2 10-11-2010 11:28 AM
Thread safety jkoshi Linux - Software 3 05-03-2007 01:03 PM
Reentrant and thread-safe code elyk Programming 2 01-04-2007 11:52 PM
Thread Safety on PHP Gerardoj Linux - General 2 03-28-2004 06:22 AM

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

All times are GMT -5. The time now is 07:29 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