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.

Real Multithreaded environment - is it possible?

I am constantly reading several TI and IAR documentations regarding MSP430F51xx features. A lot of features caught my attention, which can improve the quality, as well as decrease code and data sizes without harming debug capabilities.

In special, reading the IAR Compiler Guide, TLS and Multi-thread is mentioned on it. But, as far as I know, is not possible to process two or more "tasks" in parallel. So, how TLS works and what is its purpose?

Thanks in advance.

  • MSP430 hardware does not have "multi-Core" and definitely cannot process multi-thread in parallel with dedicated core for each thread. But it is possible to handle multi-thread with proper code. I think IAR compiler is capable of generating such proper code. But you will need to rebuild some of their libraries for that propose. I think IAR also offers RTOS that handles multi-task. In that case, the libraries are already rebuild the proper way.

    I do not know if you call that real multi-task or real multi-thread or not.

  • First of all, @old_cow_yellow thanks for the reply.

    My understanding is that a thread would be a "struct" tightly coupled to the microcontroller intrinsics, which would be used to take advantage of its features (in a general concept, not precisely talking about MSP430). If so, that would make it perform better than a software-implemented task struct (like on a small footprint RTOS). That doesn't mean that it necessarily needs to operate tasks/threads simultaneously/in parallel (aka no multicore internal structure).

    I did this question just to know if there's examples on how to implement one on MSP430, or if such programming is "too complex to make it worth", unless a compiler-level programming is done. Nevertheless, does someone know an example or tutotial that could be checked?

  • Some years ago, I implemented a very small but efficient thread switcher that does preemptive multitasking, with thread priority and thread sleep (timer or event based like UART done).

    Only a few 100 bytes code (well, the timer code was already there).
    However, it is not a simple job, as it requires stack switching and must be done in assembly language.
    Basically, a timer interrupt is triggered in regular intervals, checks which thread should be executed next, then stores all registers on stack, switches the stack pointer to the stack of the next thread and restores all registers form there, then ‘returns’ to the now ‘active’ thread.
    The interrupted thread won’t notice that it has been interrupted for perhaps a long time (depending on priority and switching granularity). It is as if an ISR has taken a long time to execute.
    Sure, having two threads running won’t double the work done. But the two (or many) threads can follow their own line of execution without caring for all the things the other one has to do.

    "My understanding is that a thread would be a "struct" tightly coupled to the microcontroller intrinsics,"
    Rather not. Intrinsics are compiler-specific pseudo-functions, to do things that are outside the scope of the C language (like messing with the processor status register).
    However, for each task you'll need a struct with meta-information, such as its separate stack (or at least teh stack position), the stafck pointer (when a different task is active), a backup of the processor registers, its priority (base and current), sleep state (delay or event trigger) and othe rinformation.
    However, teh task itself is just normal program code that is executed and doesn't notice (but shoudl be awar, in case of timing-critical actions) that it may be interrupted for some time (whie la different task follows its own program flow).

  • Ok, so using multi-thread will be a good improvement for RTOS performance, considering the processor has enough resources to operate one.

    Anyway, I didn't realize that using threads is part of DLIB support. So I found this: http://supp.iar.com/FilesPublic/UPDINFO/005691/arm/doc/infocenter/DLIBThreadSupport.html

    I think I'm going into the right direction, so using this as a starting point with IAR for MSP430, multi-thread can be achieved.

    Thanks for helping.

  • Multi-threading and performance are not necessarily related. You can lose performance by multi-threading (you actually have some time and data overhead for the thread management) while code that e.g. uses a state machine in a signle thread might be more efficient.
    However, using multiple threads is convenient and makes programs easier to write (if the threads are really independent) and also simplifies maintenance.

**Attention** This is a public forum