Getting errno in a Multithreaded program


 
Thread Tools Search this Thread
Top Forums Programming Getting errno in a Multithreaded program
# 1  
Old 12-31-2001
Getting errno in a Multithreaded program

In Tru64 Unix, the 'errno' variable is not thread safe.
Could anybody help me about how to make it thread safe or how to check 'errno' in a Multithreaded program ????

The Programming process is like this.

There are some definite number of threads having their own task.
There is one particular thread which tries to read from Disk.
We know that there can be n-number of possibilities for a read to fail. So, depeinding upon the error number thrown from a read failure., I call appropriate thread to take some action .

This task works fine when implemented as a Monolithic Program (i.e., non-multi threaded approach) but since my program is a multithreaded I'm not able to get the appropriate error no. as it is not thread safe.

So, can any body help me out with some technic/method of getting/traping out the appropriate errno.

Thanks in advance.
# 2  
Old 12-31-2001
Each thread gets it's own copy of the global variable: errno. This is done automatically by the Threads Library. So, have fun!!! Smilie

Rgds
SHAIK
shaik786
# 3  
Old 03-25-2002
Sorry for the Delayed Update.

In case of Multi Threaded Programming., just before including the
pthread.h file just define _REENTRANT., then the system will take care of making the errno thread safe.

Ex:-

#define _REENTRANT

#include <pthread.h>

main()
{
}

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Errno.h symbols

Hi, I need to look at a recent copy of /usr/include/errno.h from AIX 7.2 to check some symbols. In particular, I'm curious if it defines EOWNERDEAD and ENOTRECOVERABLE. Can someone who has access to 7.2 please check for me? Thanks! (1 Reply)
Discussion started by: topcat
1 Replies

2. Programming

does perror() set errno?

here the program gives a odd result: #include <stdio.h> int main(){ perror("first"); perror("next"); return 0; } result: first: Success next: Illegal seek why? any resonable explanation? i found no information about this in man pages. thanks in advance (2 Replies)
Discussion started by: ebd
2 Replies

3. Programming

Basic multithreaded program

I'd like to write a program (I'm flexible on language; C/C++ was my original idea but a scripting language would probably be better) that runs hundreds of programs, but only N = 4 (say) at a time. The idea is to keep all the cores on a multicore machine busy. How can I do this? In particular,... (6 Replies)
Discussion started by: CRGreathouse
6 Replies

4. UNIX for Advanced & Expert Users

forking in multithreaded program

hi all, i am using pthreads. What will happen if a thread does a fork? will all the threads are duplicated for the new process or only the called thread is duplicated? are the resources shared across the processes? thank you (0 Replies)
Discussion started by: skyrulz
0 Replies

5. Shell Programming and Scripting

execute command multithreaded util without programming

Hello all is there any way in unix to execute command in multithreaded way without doing it in java or cpp can one of the scripts handle multithread execution ? i need to test server requests ( corba ) in multithread Thanks (0 Replies)
Discussion started by: umen
0 Replies

6. Programming

errno

Hey, Can I assume that for certain function calls, errno can never be set to a certain value. More specifically, can I assume that for if the stat function call fails, the errno can never be or "No space left on device." I am assuming that a read function cannot fail because of no space... (5 Replies)
Discussion started by: the_learner
5 Replies

7. Programming

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

8. Linux

getting problem in my code:::: plz help...(multithreaded appn with serial comm.)

hello, here I am copying my code... I am using two threads for reading and writing at com ports....one for reading and one for writing...in read thread I am using select() api....and polling again and again if there is some data to be read....but select is not returning any positive value so... (0 Replies)
Discussion started by: arunchaudhary19
0 Replies

9. Programming

Hi errno in sys/stat.h

How should I use errno in a c program and what info does it have . I am working with directories and files. So can any one tell me How to access errno?I am using the stat() function on \etc directory and I am alble to access only the half of the directories.I am not able to access other half and... (6 Replies)
Discussion started by: vijlak
6 Replies

10. Programming

errno pb

Hello, I need to make a lib with pthread, when I run my make file all is good. But when I run my test program, I test errno in the begining and is already set to 251. Is it normal ??? What can I modify in my Makefile to have errno set to 0 ??? Thanks $make gcc -D_REENTRANT -shared -fpic... (3 Replies)
Discussion started by: dts
3 Replies
Login or Register to Ask a Question