Semaphore with Main Thread and Preemptive Thread

There was a long discussion in the betas about this topic: https://forum.xojo.com/t/criticalsection-semaphore-preemptive-thread-changes/81554/40

It’s probably good to revisit it here.

It sounds like you can’t have a Semaphore or CriticalSection that protects both a Cooperative and Preemptive thread at the same time.

But can you use a Semaphore or CriticalSection that protects a Preemptive Thread and the Main Thread? I’m not clear on this

Yes.

So does this mean that the Main thread, even though would cooperate and share time with other Cooperative threads, should not itself be thought of a “Cooperative Thread” ?

I think that’s where I’m getting confused.

Does this sound correct:

A Semaphore or CriticalSection can work with

  • The Main Thread and one or more Cooperative Threads
  • The Main Thread and one or more Preemptive Threads

But will not work with

  • A cooperative thread (which is not the Main thread) and one or more Preemptive Threads
1 Like

Correct.

I’ve logged the following case to see if anything can be done to improve the situation:

https://tracker.xojo.com/xojoinc/xojo/-/issues/77256

1 Like