void produce_response(Writer& out, const int result) {
     out.write("{\"scans\":[");
     bool first = true;
     ScanEntry& entry = read_;
     while (!result && !wiced_rtos_pop_from_queue(&queue_, &entry, WICED_NEVER_TIMEOUT)) {
         if (entry.done)
             break;
         if (!*entry.ssid)
             continue;
         if (first)
             first = false;
         else
             write_char(out, ',');
         write_char(out, '{');
         write_json_string(out, "ssid", entry.ssid);
         write_char(out, ',');
         write_json_int(out, "rssi", entry.rssi);
         write_char(out, ',');
         write_json_int(out, "sec", entry.security);
         write_char(out, ',');
         write_json_int(out, "ch", entry.channel);
         write_char(out, ',');
         write_json_int(out, "mdr", entry.max_data_rate);
         write_char(out, '}');
     }
     out.write("]}");
     wiced_rtos_deinit_queue(&queue_);
 }
 /**
  * Initializes the scan queue, and start a scan using the WICED wifi scan api.
  *
  */
 int process() {
     int result = wiced_rtos_init_queue(&queue_, NULL, sizeof(ScanEntry), 5);
     if (!result) {
         result = wiced_wifi_scan_networks(scan_handler, this);
         if (result)
             wiced_rtos_deinit_queue(&queue_);
     }
     return result;
 }
wiced_result_t wiced_rtos_delete_worker_thread( wiced_worker_thread_t* worker_thread )
{
    if ( wiced_rtos_delete_thread( &worker_thread->thread ) != WICED_SUCCESS )
    {
        rk_printf("iced_rtos_delete_thread delfail\n");
        return WICED_ERROR;
    }

    if ( wiced_rtos_deinit_queue( &worker_thread->event_queue ) != WICED_SUCCESS )
    {
        rk_printf("wiced_rtos_deinit_queue delfail\n");
        return WICED_ERROR;
    }

    return WICED_SUCCESS;
}
wiced_result_t wiced_rtos_create_worker_thread( wiced_worker_thread_t* worker_thread, uint8_t priority, uint32_t stack_size, uint32_t event_queue_size )
{
    memset( worker_thread, 0, sizeof( *worker_thread ) );

    if ( wiced_rtos_init_queue( &worker_thread->event_queue, "worker queue", sizeof(wiced_event_message_t), event_queue_size ) != WICED_SUCCESS )
    {
        return WICED_ERROR;
    }

    if ( wiced_rtos_create_thread( &worker_thread->thread, WICED_PRIORITY_TO_NATIVE_PRIORITY( priority ), "worker thread", worker_thread_main, stack_size, (void*) worker_thread ) != WICED_SUCCESS )
    {
        wiced_rtos_deinit_queue( &worker_thread->event_queue );
        return WICED_ERROR;
    }

    return WICED_SUCCESS;
}