Solved

library and thread general question

Posted on 2003-12-09
3
250 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
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 30 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
memory mapped I/O query 6 147
Inorder binary search tree 5 163
Parsing XML instructions in Java/any other language.... 3 110
Using ANSI C how to Read a .csv file 10 79
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now