CheckThread in C?

Moderators: TomKerekes, dynomotion

Post Reply
HowHardCanItBe
Posts: 21
Joined: Tue Nov 20, 2018 5:39 pm
Location: Sharonville, Ohio

CheckThread in C?

Post by HowHardCanItBe » Tue Oct 20, 2020 8:06 pm

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.

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: CheckThread in C?

Post by TomKerekes » Tue Oct 20, 2020 10:54 pm

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
}
Regards,

Tom Kerekes
Dynomotion, Inc.

HowHardCanItBe
Posts: 21
Joined: Tue Nov 20, 2018 5:39 pm
Location: Sharonville, Ohio

Re: CheckThread in C?

Post by HowHardCanItBe » Wed Oct 21, 2020 7:27 pm

Awesome. I had forgotten all about bitwise operators.
Shouldn't it be (instead of CurrentThread);

Code: Select all

if (ThreadActive & 2){}

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: CheckThread in C?

Post by TomKerekes » Wed Oct 21, 2020 7:40 pm

Oops. Yes.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply