Skip to content

Teensy 4.1 - simple code won't work #41

@mateusz-kusmierz

Description

@mateusz-kusmierz

I've tried running teensyThreads, so I made below code as proof of concept, but it does not work correctly.
Whats the issue?

#include <TeensyThreads.h>

volatile int counter1 = 0;
volatile int counter2 = 0;
volatile int counter3 = 0;

void thread1_func() {
  while(1) 
  {
    Serial.printf("thread 1 => %d\n",counter1++);
    delay(5000);
  }
}

void thread2_func() {
  while(1) 
  {
    Serial.printf("thread 2 => %d\n",counter2++);
    delay(500);
  }
}


void setup() {
  Serial.begin(115200);

  threads.addThread(thread1_func);
  threads.addThread(thread2_func);
}

void loop() 
{
Serial.printf("loop => %d\n",counter3++);
delay(2000);
}

Serial Monitor output:

thread 1 => 0
thread 2 => 0
loop => 1
loop => 2
loop => 3
loop => 4
loop => 5
loop => 6
loop => 7
loop => 8
loop => 9
loop => 10
loop => 11
loop => 12
loop => 13
loop => 14
loop => 15
loop => 16
loop => 17
loop => 18
loop => 19
loop => 20
loop => 21
loop => 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions