Re: Calling libiptc API from a separate thread in a C program throws segmentati



On 2012-01-17, Richard Kettlewell <rjk@xxxxxxxxxxxxxxx> wrote:
Kaz Kylheku <kaz@xxxxxxxxxxx> writes:
Jorgen Grahn <grahn+nntp@xxxxxxxxxxxxxx> wrote:
At one point -pthread was equivalent to -D_REENTRANT and -lpthread,
but that may change in the future if it has not already; it's better
to use the -pthread interface.

Either the gcc manual is incomplete, or your explanation is not

Whom are you going to believe, me or the GCC manual? :)

errno ends up indirected either way though (at least here).

"Either way" between which alternatives?

The -pthread option will have the effect of defining _REENTRANT so that
__errno_location ends up used. But -lpthread alone will not.

In /usr/include/bits/errno.h you have this:

# ifndef __ASSEMBLER__
/* Function to get address of global `errno' variable. */
extern int *__errno_location (void) __THROW __attribute__ ((__const__));

# if !defined _LIBC || defined _LIBC_REENTRANT
/* When using threads, errno is a per-thread value. */
# define errno (*__errno_location ())
# endif
# endif /* !__ASSEMBLER__ */

This part is included in /usr/include/errno.h, which then has this:

#ifndef errno
extern int errno;
#endif
.



Relevant Pages

  • Re: x86, ARM, PARISC, PPC, MIPS and Sparc folks please run this
    ... If it says the store buffer isn't coherent, ... is returned and `errno' is set. ... open_shared_memory_file (int use_tmp_file) ...
    (Linux-Kernel)
  • x86, ARM, PARISC, PPC, MIPS and Sparc folks please run this
    ... physically tagged cache moves data among cache lines, ... is returned and `errno' is set. ... open_shared_memory_file (int use_tmp_file) ...
    (Linux-Kernel)
  • Re: x86, ARM, PARISC, PPC, MIPS and Sparc folks please run this
    ... is returned and `errno' is set. ... open_shared_memory_file (int use_tmp_file) ...
    (Linux-Kernel)
  • Re: Proposal for the C library in the new standard
    ... those two pointer arguments will be addresses of objects and the chances of "lineptr" or "n" being null pointers will be negligible: ... If no characters were read, and the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-of-file indicator for the stream shall be set and the function shall return -1. ... If an error occurs, the error indicator for the stream shall be set, and the function shall return -1 and set errno to indicate the error. ... interface like the one I proposed. ...
    (comp.std.c)
  • Re: Code snippet in UNPv1
    ... Select(maxfdp1, &rset, &wset, NULL, NULL); ... if (errno!= EWOULDBLOCK) ...
    (comp.unix.programmer)