errno threadsave?

Hi,

I am thinking about the global error variable ‘errno’. Since data is shared between threads, is using ‘errno’ threadsave?

TIA
Peter

Peter St??ckigt <stoeckigt.p@stn-atlas.de> wrote:

Hi,

I am thinking about the global error variable ‘errno’. Since data is shared between threads, is using ‘errno’ threadsave?

Yup. Take a look at <sys/storage.h> to see the trick. Just grep for “errno”.

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Robert Krten <nospam83@parse.com> wrote:

Peter St??ckigt <> stoeckigt.p@stn-atlas.de> > wrote:
Hi,

I am thinking about the global error variable ‘errno’. Since data is shared between threads, is using ‘errno’ threadsave?

Yup. Take a look at <sys/storage.h> to see the trick. Just grep
for “errno”.

Actually, in sys/storage.h it would be int *errptr in the
_thread_local_storage structure.

And, if you look at errno.h you will see errno isn’t actually a simple
global variable – it is:

#define errno (*_STD __get_errno_ptr)()

That is, the dereference of the return value of a function.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

David Gibbs <dagibbs@qnx.com> wrote:

Robert Krten <> nospam83@parse.com> > wrote:
Peter St??ckigt <> stoeckigt.p@stn-atlas.de> > wrote:
Hi,

I am thinking about the global error variable ‘errno’. Since data is shared between threads, is using ‘errno’ threadsave?

Yup. Take a look at <sys/storage.h> to see the trick. Just grep
for “errno”.

Actually, in sys/storage.h it would be int *errptr in the
_thread_local_storage structure.

Oops. I was so close :slight_smile:

Cheers,
-RK

And, if you look at errno.h you will see errno isn’t actually a simple
global variable – it is:

#define errno (*_STD __get_errno_ptr)()

That is, the dereference of the return value of a function.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

David Gibbs <dagibbs@qnx.com> wrote:
: Actually, in sys/storage.h it would be int *errptr in the
: _thread_local_storage structure.

: And, if you look at errno.h you will see errno isn’t actually a simple
: global variable – it is:

: #define errno (*_STD __get_errno_ptr)()

I’ve added a note about threads to the docs for errno in the Library
Reference. There’s already a description of this buried in “Local storage
for private data” in the docs for ThreadCreate().


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Thankfully, errno is one of the things they did very right in QNX6.

In QNX4 errno wasn’t thread safe. It made threads in QNX4 somewhat of a
joke. After all, the reason that you’d want threads is frequently for
multiple IO operations. If you did an IO that failed you couldn’t reliably
tell why it failed.

“Robert Krten” <nospam83@parse.com> wrote in message
news:al7f7n$o3d$1@inn.qnx.com

Peter St??ckigt <> stoeckigt.p@stn-atlas.de> > wrote:
Hi,

I am thinking about the global error variable ‘errno’. Since data is
shared between threads, is using ‘errno’ threadsave?

Yup. Take a look at <sys/storage.h> to see the trick. Just grep for
“errno”.

Cheers,
-RK


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.