Page 1 of 1

CheckThread in C?

Posted: Tue Oct 20, 2020 8:06 pm
by HowHardCanItBe
Is there a C code equivalent for the script command CheckThread?
Something similar to ThreadExecuting(int thread) in the C# file KM_Controller.cs.

I don't want other threads (homing, etc.) to run unless thread 1 (initialization thread with forever loop) is running.

Re: CheckThread in C?

Posted: Tue Oct 20, 2020 10:54 pm
by TomKerekes
Check the variable ThreadActive.

A test for bit 1 would be:

Code: Select all

extern volatile int ThreadActive;  // one bit for each thread    

if (CurrentThread & 2)
{
    // Thread 1 is running
}

Re: CheckThread in C?

Posted: Wed Oct 21, 2020 7:27 pm
by HowHardCanItBe
Awesome. I had forgotten all about bitwise operators.
Shouldn't it be (instead of CurrentThread);

Code: Select all

if (ThreadActive & 2){}

Re: CheckThread in C?

Posted: Wed Oct 21, 2020 7:40 pm
by TomKerekes
Oops. Yes.