global variables within library __thread

mmanfred mx2927@gmail.com
Sun Oct 18 16:35:00 GMT 2015



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



More information about the Libc-help mailing list