3 Replies Latest reply on Aug 2, 2016 1:05 AM by JeGu_2199941

    Confused about built-in worker thread priorities


      In WICED/RTOS/<ThreadX or FreeRTOS>/WICED/rtos.h there are such comments :


      /* Configuration of Built-in Worker Threads


      * 1. wiced_hardware_io_worker_thread is designed to handle deferred execution of quick, non-blocking hardware I/O operations.

      *    - priority         : higher than that of wiced_networking_worker_thread

      *    - stack size       : small. Consequently, no printf is allowed here.

      *    - event queue size : the events are quick; therefore, large queue isn't required.


      * 2. wiced_networking_worker_thread is designed to handle deferred execution of networking operations

      *    - priority         : lower to allow wiced_hardware_io_worker_thread to preempt and run

      *    - stack size       : considerably larger than that of wiced_hardware_io_worker_thread because of the networking functions.

      *    - event queue size : larger than that of wiced_hardware_io_worker_thread because networking operation may block



      But in WICED/RTOS/wiced_rtos_common.c, wiced_result_t wiced_rtos_init( void ) creates those worker threads as this :






      And the priority macros are defined in include/wiced_defaults.h


      #define WICED_NETWORK_WORKER_PRIORITY      (3)

      #define WICED_DEFAULT_WORKER_PRIORITY      (5)


      All above are the same for both SDK-3.5.2 & 3.7.0, (also both for ThreadX & FreeRTOS).

      Got confused about those RED sections above, they doesn't look consistent to me.

      To follow the "design" I think it should be modified that WICED_HARDWARE_IO_WORKER_THREAD is created with priority < 3.

      Or the comments should be modified so people are not misled and can use them correctly.


      (It's interesting that this is not mentioned in this old post : Worker IO Thread Priority is lower than Network IO thread priority ? .
        Iis a bug introduced in recent SDK versions?)

        • 1. Re: Confused about built-in worker thread priorities

          Hi JeGu_2199941


          I agree with your comment, it's really confusing.

          Either the comment or the code is wrong.


          Note, there is a thread priority bug fix in wiced_rtos_create_worker_thread() which is not mentioned in ChangeLog.

          You can compare the implementation of wiced_rtos_create_worker_thread() between 3.5.2 and 3.7.0.

          But after reading your post, I suspect the old code happens to be correct.

          Really needs the official WICED team to clarify.



          • 2. Re: Confused about built-in worker thread priorities

            Hi AxLi_1746341

            I agree with you that the implementation of wiced_rtos_create_worker_thread() is different between versions.

            But I think the new one in SDK-3.7.0 is correct.


            In SDK-3.5.2 : worker thread priority is reversed twice for FreeRTOS

                 RTOS/wiced_rtos_common.c => wiced_result_t wiced_rtos_create_worker_thread() :


                      wiced_rtos_create_thread(..., WICED_PRIORITY_TO_NATIVE_PRIORITY( priority ), ...);


                 RTOS/FreeRTOS/WICED/wiced_rtos.c => wiced_result_t wiced_rtos_create_thread) :


                      return host_rtos_create_thread_with_arg(..., WICED_PRIORITY_TO_NATIVE_PRIORITY( priority ), ...);



                      result = (wiced_result_t) host_rtos_create_thread_with_arg(..., priority, ...);



            In SDK 3.7.0 : worker thread priority is only reversed for FreeRTOS & NuttX as expected





            1 of 1 people found this helpful
            • 3. Re: Confused about built-in worker thread priorities


              Could you drop some comment about the original problem (about WICED_HARDWARE_IO_WORKER_THREAD) ?