ftrias / TeensyThreads

MIT License
178 stars 26 forks source link

What am I doing wrong here? #43

Closed ipmcc closed 4 months ago

ipmcc commented 4 months ago

Starting from the example in the readme I did this. It doesn't work. Can anyone tell me why?

#include <TeensyThreads.h>
volatile int count = 0;

std::mutex foo;

void thread_func(int data){
  Threads::Scope scope(foo);
  while(1) count += data;
}
void setup() {
  std::thread th1(thread_func, 1);
  th1.detach();
}
void loop() {
  Threads::Scope scope(foo);
  Serial.println(count);
}

Edit: Never mind. I'm dumb. I'd delete this, but I can't figure out how. The trick is that "threads" work like threads and not like the loop() method.