Skip to content

Sync time and unsubscribe called on the system thread#1041

Merged
technobly merged 1 commit intodevelopfrom
feature/sync-time-multithread
Jun 25, 2016
Merged

Sync time and unsubscribe called on the system thread#1041
technobly merged 1 commit intodevelopfrom
feature/sync-time-multithread

Conversation

@monkbroc
Copy link
Copy Markdown
Member

@monkbroc monkbroc commented Jun 20, 2016

Fixes #904

Calling Particle.syncTime() in a multithreaded app has a small chance of crashing the system if the system thread is currently calling network functions too.

The fix is to call Particle.syncTime() on the system thread.

App to reproduce:

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

void setup()
{
  Serial.blockOnOverrun(true); //don't ever block for serial integrity
  Serial.begin(9600);

  WiFi.on();
  WiFi.connect();
  Particle.connect();

  Serial.println("breatheGreen5");
}

static unsigned long millisOfLastPublish = 0;
static unsigned long millisOfLastTimeSync = 0;

void loop()
{
  Particle.process();

  if( Particle.connected() )
  {
    if( ( millis() - millisOfLastPublish ) > (unsigned long)random(260, 500) )
    {
      millisOfLastPublish = millis();
      Serial.println("Publishing event");
      Particle.publish("event", " fjksdas " + String(millisOfLastPublish) );
    }

    if( ( millis() - millisOfLastTimeSync ) > 1 )
    {
      Serial.println("timeSync: " + String( Particle.syncTime() ) );
      millisOfLastTimeSync = millis(); 
    }
  }
}

Doneness:

  • Contributor has signed CLA
  • Problem and Solution clearly stated
  • Code peer reviewed
  • API tests compiled
  • Run unit/integration/application tests on device
  • Add documentation
  • Add to CHANGELOG.md after merging (add links to docs and issues)
    Prevents issues when multiple threads try to send messages through the cloud connection or manage the network state shared memory.

Prevents issues when multiple threads try to send messages through the cloud connection or manage the network state shared memory.
@m-mcgowan m-mcgowan self-assigned this Jun 20, 2016
@m-mcgowan m-mcgowan added this to the 0.6.x milestone Jun 20, 2016
@technobly technobly merged commit 1c22de8 into develop Jun 25, 2016
@technobly technobly deleted the feature/sync-time-multithread branch October 27, 2016 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Photon stuck on breathing green

4 participants