This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: global variables within library __thread
- From: mmanfred <mx2927 at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Sun, 18 Oct 2015 18:35:17 +0200
- Subject: Re: global variables within library __thread
- Authentication-results: sourceware.org; auth=none
- References: <CANr2zYiGV9dnNX4N6u0NhnZ7EYp7eXRUPUYuUe777eRQcA5WRQ at mail dot gmail dot com> <20151017025123 dot GD28215 at vapier dot lan> <CANr2zYjWBZsyd1CDOgC6JryYZcEyuk+P9YSXbRLZwSgZiH6Ldg at mail dot gmail dot com> <CANr2zYjRZNQhUYXjHPW9_DJ3WbBE_GdVkFKW=hkzqEt=dQ4jrA at mail dot gmail dot com> <CANr2zYi2jcUPA7Y3eOE6mMigWryMKa5TesAXM5_NF43-ZriK_w at mail dot gmail dot com> <CANr2zYjzeLwi8c=gSKqcx7fZJ1zHgKs0MK9woou55Zm_=DoC5g at mail dot gmail dot com>
On 10/17/2015 10:21 PM, JoÃl KrÃhemann wrote:
Hi
compile like this works - ags_thread-posix.h:
static __thread AgsThread *ags_thread_self;
Looks like the correct header file would be:
extern __thread AgsThread *ags_thread_self;
Which is what Mike Frysinger suggested earlier.
and within source file - ags_thread-posix.c:
extern __thread AgsThread *ags_thread_self;
Looks like the correct source file would be:
__thread AgsThread *ags_thread_self;
but is it correct?
You may want to check the usage of the static and extern keywords
cheers,
JoÃl
On Sat, Oct 17, 2015 at 5:58 PM, JoÃl KrÃhemann <weedlight@gmail.com> wrote:
Hi
Putting into header has same effect as static global, isn't it?
static global is as far as I now how you do a semaphore.
On Sat, Oct 17, 2015 at 5:56 PM, JoÃl KrÃhemann <weedlight@gmail.com> wrote:
... and as told these variables should be per process so putting into header
is definitively no option, think so.
On Sat, Oct 17, 2015 at 5:49 PM, JoÃl KrÃhemann <weedlight@gmail.com> wrote:
Hi
First of all it is located in the ags_thread-posix.c file but as
putting it into the header i get
something like:
/usr/bin/ld: ags_thread_self: TLS definition in gsequencer-main.o
section .tbss mismatches non-TLS reference in .libs/gsequencerS.o
.libs/gsequencerS.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
libtool: link: rm -f ".libs/gsequencerS.o"
Makefile:2010: recipe for target 'gsequencer' failed
make[1]: *** [gsequencer] Error 1
make[1]: Leaving directory '/home/joelkraehemann/gsequencer'
Makefile:1854: recipe for target 'all' failed
make: *** [all] Error 2
This reference isn't used anywhere but in ags_thread-posix.c. Further
main.c doesn't contain any
references to it. For completion here's the code of the functions using it:
void
ags_thread_resume_handler(int sig)
{
if(ags_thread_self == NULL){
return;
}
#ifdef AGS_DEBUG
g_message("thread resume\0");
#endif
g_atomic_int_and(&(ags_thread_self->flags),
(~AGS_THREAD_SUSPENDED));
ags_thread_resume(ags_thread_self);
}
void
ags_thread_suspend_handler(int sig)
{
#ifdef AGS_DEBUG
g_message("thread suspend\0");
#endif
if(ags_thread_self == NULL){
return;
}
if ((AGS_THREAD_SUSPENDED &
(g_atomic_int_get(&(ags_thread_self->flags)))) != 0) return;
g_atomic_int_or(&(ags_thread_self->flags),
AGS_THREAD_SUSPENDED);
ags_thread_suspend(ags_thread_self);
do sigsuspend(&(ags_thread_self->wait_mask)); while
((AGS_THREAD_SUSPENDED &
(g_atomic_int_get(&(ags_thread_self->flags)))) != 0);
}
cheers,
JoÃl
On Sat, Oct 17, 2015 at 4:51 AM, Mike Frysinger <vapier@gentoo.org> wrote:
On 17 Oct 2015 00:31, JoÃl KrÃhemann wrote:
__thread AgsThread *ags_thread_self = NULL;
/usr/bin/ld: ags_thread_self: TLS definition in
/home/joelkraehemann/gsequencer/.libs/libags_thread.a(libags_thread_la-ags_thread-posix.o)
section .tbss mismatches non-TLS reference in .libs/gsequencerS.o
make sure the header that declares this also has __thread markings.
declaring it in the header like this would be wrong:
extern AgsThread *ags_thread_self;
-mike