Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

library and thread general question

Posted on 2003-12-09
3
Medium Priority
?
274 Views
Last Modified: 2010-04-15
What are in <unistd.h> and <stdlib.h> ?  

To compile a thread on linux, we type

$cc -D_REENTRANT threadprog.c -o threadprog -lpthread

what does -D_REENTRANT do?  

Thanks

MD
0
Comment
Question by:mfaa
[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 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9905843
When compiling code that uses threads we have to define the  _REENTRANT macro so that the thread-safe system functions are used instead.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 120 total points
ID: 9910354
 
Reentrant is an adjective that describes a computer program or routine that is written so that the same copy in memory can be shared by multiple users. Reentrant code is commonly required in operating systems and in application programs intended to be shared in multi-use systems. A programmer writes a reentrant program by making sure that no instructions modify the contents of variable values in other instructions within the program. Each time the program is entered for a user, a data area is obtained in which to keep all the variable values for that user. The data area is in another part of memory from the program itself. When the program is interrupted to give another user a turn to use the program, information about the data area associated with that user is saved. When the interrupted user of the program is once again given control of the program, information in the saved data area is recovered and the program can be reentered without concern that the previous user has changed some instruction within the program.

In a multithreaded environment, it is not uncommon to have race conditions
A race condition is what occurs when multiple threads read and write to the same memory without proper synchronization, resulting in an incorrect value being read or written. The result of a race condition may be a bit pattern which isn't even a valid value for the data type. A race condition results in undefined behavior.

A program is thread-safe if it has no race conditions, does not deadlock, and has no priority failures.Note that thread-safety does not necessarily imply efficiency, and than while some thread-safety violations can be determined statically at compile time, many thread-safety errors can only only be detected at runtime.

The -D_REENTRANT flag tells the compiler to enable reentrant flag which will lead to compiling and usage of thread safe functions
0
 

Author Comment

by:mfaa
ID: 9912193
Thanks for the reply...your help was greatly appreciated!

MD
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

715 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