3

What is the advantage of using FreeRTOS when using GCC C11? E.g in C11 I have threading and queues etc, so therefore I don't need FreeRTOS, or not?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Jan
  • 89
  • 7

4 Answers4

4

Threads support is optional in the C11 standard, and their implementation would be part of the C library, not GCC itself (see here). I don't know of any C library running on embedded devices which implemented C11 threads (at least newlib does not), so at the moment C11 threads are not an option, except if you plan to implement them yourself.

C11 threads are also not optimised for embedded systems, and you could therefore not specify their stack size.

I don't know of any queue support in C11, maybe you were thinking to C++11 queues. By not using FreeRTOS you would therefore have to implement your own queues.

Étienne
  • 4,773
  • 2
  • 33
  • 58
1

RTOS's provide more than just thread support, they provide a scheduling mechanism. Look up information on "time and space partitioning" to get a better idea of what an RTOS will provide for your project. Some other things to search would be "round robin scheduling" and "priority preemptive scheduling".

As a matter of fact the book for FreeRTOS is well written and covers these concepts. I think it is $35.

  • Tanks for the info, I will take a look at it. Deciding if I should use C++ vs C or RTOS vs C11 on a micro-controller like the NPX1768 stays hard. I'm not that experienced with the overhead it gives on execution speed and memory. Especially now the micro-controllers has become more powerful. – Jan Feb 01 '15 at 14:12
0

The comparison between C11 and FreeRTOS is really not an apples to apples comparison. C11 is a language (standard) while FreeRTOS is a kernel+OS.

C11 presumably can be run on top of an RTOS or a more traditional kernel+OS like Linux.

What you should be comparing is RTOS vs a traditional kernel+OS. An RTOS is specifically designed for real time response from the kernel. This is accomplished by making the kernel preempt-able at a very fine granularity, which allows higher priority computation to run as soon as it is ready to run. This is not always possible in a traditional kernel, because there are parts of the kernel that are not preempt-able.

An RTOS is also optimized to minimize arbitrary delays in the kernel like file system sync, garbage collection, etc. The user-space to kernel-space context switch is much more efficient because the entire system really runs in a single address space and security ring. There is usually no virtual memory, which serves to eliminate a huge amount of overhead involved in process to process context switches, because virtual memory page tables don't need to be swapped and built up from scratch on each context switch. The latter is obviously at the expense of isolation between threads of computation. Interrupt handling is also optimized for minimal overhead.

Ziffusion
  • 8,779
  • 4
  • 29
  • 57
-1

Tank you very much for your info. Its very helpful. I'm using the NPX LPCXpresso for the ARM Cortex M3. That one should support (parts) of the C11. At least I see the libs mutex and thread in e.g.

tools\arm-none-eabi\include\c++\4.8.3\thread

But for now it didn't work. For me it's not completely clear if there is a difference in support for newlib or redlib and which libs it uses. And which toolchain is the best to use. (This ARM is quite new for me).

Do I understand you right that from point of view of

efficiency speed, stability, efficiency memory support,

It's better to use FreeRTOS?

My first impression was that FreeRTOS would generate much more overhead than standard C libs (if they would be there) but it's just the opposite (even when there would be a thread lib for newlib)?

Jan
  • 89
  • 7
  • Is the header file you are referring to not a C++ header? The problem with C library threads is that you can not specify the stack size, which is very important in embedded systems. It does not seem usable in your case. – Étienne Aug 20 '14 at 21:15
  • Ok thank you. Then I go for FreeRTOS. B.t.w. I'm writing in C++. So it's a C++ header. But then I have a c++ library? – Jan Sep 03 '14 at 21:58
  • Yes, C++ headers are part of the C++ standard library. By the way you should rather edit your question or add comments when you want to ask clarifications, instead of posting it as an answer. – Étienne Sep 04 '14 at 20:42