[ISSUE] "Thread" reference not recognized in Workbench

When using Threads, Workbench flags any references to Thread as an error, undefined, despite successful compiling using the CLI, and not flagging in Particle Dev.

If I run with all extensions disabled (including Particle ones) no errors of any kind are flagged in the file. As soon as I enable Particle Workbench (and prereqs “C/C++” and “Cortex-Debug”) the issue presents itself again.

My best guess is that since PLATFORM_THREADING is defined in firmware/platform/MCU/build.mk and not in a header file VS Code doesn’t have the context to recognize it. Can this parameter and others normally set under those build files be established based off of the Particle: Configure Workspace For Device selection?

The sample code to reproduce the issue:

Thread mythread;

void threadFunction() { for(;;) { delay(100); } }

void setup() {
  // See Thread is not recognized
  mythread = Thread("ThreadName", threadFunction, OS_THREAD_PRIORITY_DEFAULT + 1);

  SINGLE_THREADED_BLOCK() {
    // This is recognized, so clearly spark_wiring_thread.h is properly included
  }

  #ifdef PLATFORM_THREADING
  // Notice that this is grayed out here, which is why Thread is not included
  // According to VS Code this is not defined
  delay(100);
  #endif
}

void loop() {}

The output of the Particle Audit:


*** WARNING: MAY CONTAIN CONFIDENTIAL INFORMATION - PLEASE SANITIZE BEFORE SHARING ***
To report an issue, visit:
https://community.particle.io/t/information-how-to-report-bugs-and-provide-feedback/44245

{
    "username": "justice@amper.xyz",
    "workspace": {
        "name": "test-particle-project (Workspace)",
        "isWorkspace": true,
        "configFile": "test-particle-project.code-workspace",
        "root": "/Users/justicereed/Documents/Engineering/Hardware/test-particle-project",
        "files": [
            ".vscode",
            ".vscode/launch.json",
            ".vscode/settings.json",
            "README.md",
            "project.properties",
            "src",
            "src/test-particle-project.ino",
            "test-particle-project.code-workspace"
        ]
    },
    "vscode": {
        "appName": "Visual Studio Code",
        "appRoot": "/Applications/Visual Studio Code.app/Contents/Resources/app",
        "machineId": "4cc4cb9a12ea10c756da5e4376e9dea6d7c38af8833f85573107faa9b6beb4e8",
        "sessionId": "400972f7-b65f-448d-9a19-7566e48853f91544116148205",
        "version": "1.29.1"
    },
    "cli": {
        "binpath": "/Users/justicereed/.vscode/extensions/particle.particle-vscode-core-1.0.0-alpha.5/src/cli/bin/darwin/amd64/particle",
        "ok": true,
        "version": "1.35.2"
    },
    "localCompiler": {
        "dependencies": [
            "deviceOS@0.7.0",
            "gcc-arm@5.3.1",
            "buildtools@1.0.1",
            "buildscripts@1.0.0",
            "deviceOS@0.6.4",
            "gcc-arm@4.9.3",
            "deviceOS@0.6.3"
        ]
    },
    "platform": {
        "os": "darwin",
        "type": "Darwin",
        "release": "17.4.0",
        "arch": "x64",
        "path": {
            "key": "PATH",
            "value": "/Users/justicereed/.nvm/versions/node/v8.9.4/bin:/Users/justicereed/Library/Python/3.6/bin:/Users/justicereed/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin"
        },
        "homeDir": "/Users/justicereed",
        "particleDir": "/Users/justicereed/.particle",
        "localCompilerToolchainDir": "/Users/justicereed/.particle/toolchains"
    },
    "env": {
        "TMPDIR": "/var/folders/60/_39c6nf109v28rbbvzcwwxnh0000gn/T/",
        "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0",
        "SHELL": "/bin/bash",
        "HOME": "/Users/justicereed",
        "Apple_PubSub_Socket_Render": "/private/tmp/com.apple.launchd.VFcXvhkwIH/Render",
        "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.Z4bCkfO4Hw/Listeners",
        "PATH": "/Users/justicereed/.nvm/versions/node/v8.9.4/bin:/Users/justicereed/Library/Python/3.6/bin:/Users/justicereed/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin",
        "LOGNAME": "justicereed",
        "XPC_SERVICE_NAME": "com.microsoft.VSCode.11736",
        "USER": "justicereed",
        "XPC_FLAGS": "0x0",
        "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}",
        "VSCODE_NODE_CACHED_DATA_DIR": "/Users/justicereed/Library/Application Support/Code/CachedData/bc24f98b5f70467bc689abf41cc5550ca637088e",
        "VSCODE_LOGS": "/Users/justicereed/Library/Application Support/Code/logs/20181205T175939",
        "VSCODE_IPC_HOOK": "/Users/justicereed/Library/Application Support/Code/1.29.1-main.sock",
        "VSCODE_PID": "80466",
        "NVM_BIN": "/Users/justicereed/.nvm/versions/node/v8.9.4/bin",
        "NVM_CD_FLAGS": "",
        "NVM_DIR": "/Users/justicereed/.nvm",
        "PWD": "/",
        "SHLVL": "1",
        "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron",
        "AMD_ENTRYPOINT": "vs/workbench/node/extensionHostProcess",
        "PIPE_LOGGING": "true",
        "VERBOSE_LOGGING": "true",
        "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/60/_39c6nf109v28rbbvzcwwxnh0000gn/T/vscode-ipc-0d036d6d-a236-4c05-af6b-9291b588d7eb.sock",
        "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true",
        "VSCODE_LOG_STACK": "undefined",
        "VSCODE_LOG_LEVEL": "undefined",
        "CRASH_REPORTER_START_OPTIONS": "{\"companyName\":\"Microsoft\",\"productName\":\"VSCode\",\"submitURL\":\"https://rink.hockeyapp.net/api/2/apps/21a48a66799e47fea4f52c0ff81e803d/crashes/upload\",\"extra\":{\"vscode_version\":\"1.29.1\",\"vscode_commit\":\"bc24f98b5f70467bc689abf41cc5550ca637088e\",\"vscode_sessionId\":\"400972f7-b65f-448d-9a19-7566e48853f91544116148205\",\"processName\":\"extensionHost\"},\"crashesDirectory\":\"/var/folders/60/_39c6nf109v28rbbvzcwwxnh0000gn/T\"}",
        "ELECTRON_RUN_AS_NODE": "1",
        "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true"
    },
    "versions": {
        "http_parser": "2.7.0",
        "node": "8.9.3",
        "v8": "6.1.534.41",
        "uv": "1.15.0",
        "zlib": "1.2.11",
        "ares": "1.10.1-DEV",
        "modules": "57",
        "nghttp2": "1.25.0",
        "openssl": "1.0.2n"
    },
    "extensions": [
        {
            "id": "ms-vscode.node-debug",
            "version": "1.29.2"
        },
        {
            "id": "ms-vscode.node-debug2",
            "version": "1.29.5"
        },
        {
            "id": "ms-vscode.references-view",
            "version": "0.0.8"
        },
        {
            "id": "marus25.cortex-debug",
            "version": "0.1.21"
        },
        {
            "id": "ms-vscode.cpptools",
            "version": "0.20.1"
        },
        {
            "id": "particle.particle-vscode-core",
            "version": "1.0.0-alpha.5"
        },
        {
            "id": "particle.particle-vscode-snippets",
            "version": "1.0.0-alpha.5"
        },
        {
            "id": "particle.particle-vscode-theme",
            "version": "1.0.0-alpha.5"
        }
    ]
}

*** WARNING: MAY CONTAIN CONFIDENTIAL INFORMATION - PLEASE SANITIZE BEFORE SHARING ***
To report an issue, visit:
https://community.particle.io/t/information-how-to-report-bugs-and-provide-feedback/44245


@justicefreed_amper wow thanks for a super-helpful report :pray::+1:

you are correct: PLATFORM_THREADING=1 needs to be added to the list of defines we are providing to the intellisense engine.

it’s a simple change - i’ll get it in the next update.

3 Likes