Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 21 Jun 2015 11:56:00 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: Problem with c++ and std::thread comparison

* Comm Unist <comm.unist@...dex.com> [2015-06-21 17:10:42 +1000]:
> What happens when you try to call a weak symbol? Do you end up calling 0x000000.....00 depending on your arch?

no

you probably encountered weak references in libstdc++
(but hard to tell based on the information you gave us)

extern weak reference will be 0 unless something else
pulls in the definition at link time.

> I ask because I have C++ program that uses std::threads. These use pthreads internally.

that's an internal detail you should not be able to observe

> There were two places where I have problems. One was with condtiion variables and the other with comparsion of std::thread ids:

> This changes seems to work, or does c++ not needs to check pthreads being equal?

if the macro definition is hidden then you get a normal
function call whenever pthread_equal is called.

c++ code must be explicitly made slower by hiding the
macro because it does not allow function like macros
(welcome to c++).

inline semantics is different in c, c++ and gcc so
you cannot make that visible outside of ifdef __cplusplus.

(but diverging code logic under ifdef is not ok
because it makes maintainance problems, the current
code seems to me the most acceptable solution).

> diff --git a/include/pthread.h b/include/pthread.h
> index 99a74a5..e97b9e4 100644
> --- a/include/pthread.h
> +++ b/include/pthread.h
> @@ -85,9 +85,7 @@ __attribute__((const))
>  pthread_t pthread_self(void);
>  
>  int pthread_equal(pthread_t, pthread_t);
> -#ifndef __cplusplus
> -#define pthread_equal(x,y) ((x)==(y))
> -#endif
> +inline int pthread_equal(pthread_t a, pthread_t b) { return a == b; }
>  
>  int pthread_setcancelstate(int, int *);
>  int pthread_setcanceltype(int, int *);

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.