diff --git a/libraries/AP_Param/AP_Param.cpp b/libraries/AP_Param/AP_Param.cpp
index df4db717ad..43350b2406 100644
--- a/libraries/AP_Param/AP_Param.cpp
+++ b/libraries/AP_Param/AP_Param.cpp
@@ -1984,21 +1984,25 @@ void AP_Param::send_parameter(const char *name, enum ap_var_type var_type, uint8
 }
 
 /*
-  return count of all scalar parameters
+  return count of all scalar parameters.
+  Note that this function may be called from the IO thread, so needs
+  to be thread safe
  */
 uint16_t AP_Param::count_parameters(void)
 {
     // if we haven't cached the parameter count yet...
-    if (0 == _parameter_count) {
+    uint16_t ret = _parameter_count;
+    if (0 == ret) {
         AP_Param  *vp;
         AP_Param::ParamToken token;
 
         vp = AP_Param::first(&token, nullptr);
         do {
-            _parameter_count++;
+            ret++;
         } while (nullptr != (vp = AP_Param::next_scalar(&token, nullptr)));
+        _parameter_count = ret;
     }
-    return _parameter_count;
+    return ret;
 }
 
 /*