TRY_LOCK was not declared in this scope WITH_LOCK was not declared in this scope

It appears that the system thread management functions for avoiding cross-talk on the Serial usb connection do not work.

I am using system threading and want to make sure that the Serial port isn’t being used by the application thread when I try to flash my Electron via USB.

The Particle Guide on this subject says that you need to use either the TRY LOCK(Serial) or WITH_LOCK(Serial) wrapper methods described in the Synchronizing Access to Shared Resources section:

https://docs.particle.io/reference/firmware/electron/#synchronizing-access-to-shared-system-resources

When I try to use either of these methods I get a compiler error message such as:

‘TRY_LOCK’ was not declared in this scope

Also throws the same errors in Particle Build.

Hi @macdonaldtomw

I believe those are tagged for 0.5.0 which is coming to the web IDE build very soon but has not been announced yet. I just checked and 0.4.9 is the latest available this writing but I know 0.5.0 is coming shortly.

If you can compile locally with gcc from the 0.5.0 release candidate you can use these.

2 Likes

These locking features are already available in 0.4.9 (for the Photon), but @macdonaldtomw is building for the Electron which is still running 0.4.8 and as such does not yet support SYSTEM_THREAD(ENABLED) on the Electron either.

It’s a pitty that the docs fail to mention this fact. But this should be temporary since 0.5.0 is just round the corner.
So for bleading edge dev, local building might be the way to go.

3 Likes

Actually, SYSTEM_THREAD(ENABLED) is working fine with 0.4.8, its just the shared resource functions try_lock() and with_lock() that aren’t working.

Really?


Or are you building with a local toolchain?

I’m building using Cloud compilation, Electron running 0.4.8

I can confirm that multithreading is working fine because I tried it with the blinky example sketch and the on-board LED started blinking immediately before the GSM modem even started trying to connect.

See screenshot (notice firmware version in sidebar, and compilation success message at bottom of screen):

I must admit that was unexpected, especially since @mdma should know - but I won’t argue :+1:

0.4.8 does in fact include the full multithreading code on the Electron, but the stack size was too small, leading to random code crashes after connecting to the cloud via UDP, which is why we were saying that multithreading wasn’t supported in 0.4.8 on the Electron. 0.5.0 fixes this.

3 Likes

Is this issue resolved now?

Have you upgraded to 0.5.0?

I’d like to, but am having a slew of problems trying to get my electron to be detected while in DFU mode (blinking yellow)

Never mind, looks like I just needed to run the zadig utility file to install the dfu drivers.

you can also update the electron while in listening mode, using particle flash --serial firmware.bin so you don’t need the DFU drivers. :smile: