This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Thread local storage

Other Parts Discussed in Thread: SYSBIOS

I am trying to use thread-local storage in a SYS/BIOS project.  I am hoping that "thread-local" storage would be implemented as "task-local" storage in the SYS/BIOS environment.

I use the SYS/BIOS > TI Target Examples > Minimal project template, and the ti.platforms.evm6657 platform.  I then add two lines to the default main.c, shown below in bold.

...
Void taskFxn(UArg a0, UArg a1)
{
    System_printf("enter taskFxn()\n");
    
    Task_sleep(10);
    
    System_printf("exit taskFxn()\n");
}

__thread unsigned int gInt = 0;

/*
 *  ======== main ========
 */
Int main()
{
    /*
     * use ROV->SysMin to view the characters in the circular buffer
     */
    System_printf("enter main()\n");
    
    gInt = 1;
    
    BIOS_start();    /* does not return */
    return(0);
}

I get the following build warnings:

  • #10015-D output file "Tls_sysbios_proj.out" cannot be loaded and run on a target system
  • #10247-D creating output section ".tdata" without a SECTIONS specification
  • #10247-D creating output section ".TI.tls_init" without a SECTIONS specification
  • #17003-D relocation from function "main" to symbol "gInt" overflowed; the 22-bit relocated address 0x202f43 is too large to encode in the 15-bit unsigned field (type = 'R_C6000_TPR_U15_W' (40), file = "./main.obj", offset = 0x00000060, section = ".text")

I can add a .tdata section to the default app.cfg > Program > Sections, but doing so does not resolve the warning.

Similarly adding a .TI.tls_init section does not resolve the warning, and adds an additional warning (xdc.cfg.Program.SectionSpec#1 : Entry for the section '.TI.tls_init' in Program.sectMap is set to 'undefined'. This section allocation will be ignored).

I tried experimenting by marking the gInt as a far variable, but that did not help.

If instead of the SYS/BIOS template, I use Empty Projects > Empty Project (with main.c), and I add the two lines related to the thread-local storage variable, it will build the executable with only two warnings

  • #10247-D creating output section ".tdata" without a SECTIONS specification
  • #10247-D creating output section ".TI.tls_init" without a SECTIONS specification

If I add the .tdata and .TI.tls_init sections to the linker command file, the .TI.tls_init warning goes away, but the .tdata warning remains.

So my question is, how do I use thread-local storage, as implemented via the __thread qualifier, on a SYS/BIOS project?

c6655, SYS/BIOS 6.42.1.20, cgt 8.1.0, CCS 6.1.1.00022

Thanks.

  • Do you specifically want to use __thread with SYS/BIOS or you are just looking for any type of local storage? SYS/BIOS tasks maintain their own stacks for local variables, and you can initialize these local variables through Task arguments.
    I can't find any SYS/BIOS example that uses thread-local storage support, but if you insist on using that, I can ask around for help.
  • I appreciate the comments.

    Ultimately I am looking for any type of local storage.

    However I was drawn to __thread for this case because the code is part of a cross-platform library, and using such a descriptor on a variable seemed to be the easiest path to a portable solution: C++11 has thread_local, Microsoft Visual C++ has __declspec(thread), etc.

    So yes, I would like to know if using __thread is an option, but in the meantime I will look into the mechanism you suggested and others to see how well they can be adapted.

    Thanks.

  • I have found that the newest SYS/BIOS release 6.46.00.23 contains a module ti.sysbios.rts.ti.ThreadLocalStorage, which support __thread functionality. However, it also requires additional compiler support that doesn't seem to be publicly available yet. When compiling, you are supposed to pass the option --multithreaded to the compiler, but the latest C6000 compiler 8.1.0 doesn't have that option. Also, there are no examples in SYS/BIOS to demonstrate the local thread storage support.
    So, it seems that support is not completely ready. My guess is that in 2-3 months, the compiler option and the examples should be available.
  • Thanks for looking into this.