* Problem with c++ and std::thread comparison
@ 2015-06-21 7:10 Comm Unist
2015-06-21 8:20 ` Jens Gustedt
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Comm Unist @ 2015-06-21 7:10 UTC (permalink / raw)
To: musl
What happens when you try to call a weak symbol? Do you end up calling 0x000000.....00 depending on your arch?
I ask because I have C++ program that uses std::threads. These use pthreads internally. 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?
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 *);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Problem with c++ and std::thread comparison
2015-06-21 7:10 Problem with c++ and std::thread comparison Comm Unist
@ 2015-06-21 8:20 ` Jens Gustedt
2015-06-21 9:56 ` Szabolcs Nagy
2015-06-21 14:52 ` Rich Felker
2 siblings, 0 replies; 4+ messages in thread
From: Jens Gustedt @ 2015-06-21 8:20 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 1938 bytes --]
Am Sonntag, den 21.06.2015, 17:10 +1000 schrieb Comm Unist:
> What happens when you try to call a weak symbol? Do you end up calling 0x000000.....00 depending on your arch?
Why do you ask? Could you be more specific in what problem you encounter?
> I ask because I have C++ program that uses std::threads.
> These use pthreads internally.
You mean you are using a C++ library that maps std::threads to
pthreads, or are you talking about a mapping to the musl C11 threads
implementation, that then shares code with musl's pthread
implementation?
(Mapping std::threads to C11 threads should clearly be the more
appropriate choice.)
> There were two places where I have problems. One was with condtiion
> variables
Just annoncing that you have problems doesn't tell us much. Describe
your problem properly, please.
and the other with comparsion of std::thread ids:
> This changes seems to work, or does c++ not needs to check pthreads being equal?
>
>
> 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; }
Why wouldn't just a declaration of the function prototype suffice?
The way you are doing this would clearly not work for C since this
would instantiate a version of the function in every translation unit.
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536 ::
:: :::::::::::::::::::::: gsm France : +33 651400183 ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Problem with c++ and std::thread comparison
2015-06-21 7:10 Problem with c++ and std::thread comparison Comm Unist
2015-06-21 8:20 ` Jens Gustedt
@ 2015-06-21 9:56 ` Szabolcs Nagy
2015-06-21 14:52 ` Rich Felker
2 siblings, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2015-06-21 9:56 UTC (permalink / raw)
To: musl
* Comm Unist <comm.unist@yandex.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 *);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Problem with c++ and std::thread comparison
2015-06-21 7:10 Problem with c++ and std::thread comparison Comm Unist
2015-06-21 8:20 ` Jens Gustedt
2015-06-21 9:56 ` Szabolcs Nagy
@ 2015-06-21 14:52 ` Rich Felker
2 siblings, 0 replies; 4+ messages in thread
From: Rich Felker @ 2015-06-21 14:52 UTC (permalink / raw)
To: musl
On Sun, Jun 21, 2015 at 05:10:42PM +1000, Comm Unist wrote:
> What happens when you try to call a weak symbol? Do you end up
> calling 0x000000.....00 depending on your arch?
What weak symbol? If your program is using weak references to pthread
symbols, that's a bug. libstdc++ has this bug upstream but it's fixed
in the patches you should be applying for building a toolchain that
targets musl.
Rich
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-21 14:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-21 7:10 Problem with c++ and std::thread comparison Comm Unist
2015-06-21 8:20 ` Jens Gustedt
2015-06-21 9:56 ` Szabolcs Nagy
2015-06-21 14:52 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).