Question on variables in multithreading Python Vex V5

I’m planning on putting my odometry system into a separate thread. My question is about how threads interact when updating shared variables.

For example, if I set a positional variable, x, to 0 in one thread, while the odometry thread is running at the same time, is it possible for the odometry thread to immediately overwrite x with a different value before the first thread finishes its task?

More generally, do threads in Vex Python execute their instructions in tandem (i.e., running at the same time), or do they alternate in some way (e.g., thread 1 executes all its instructions for one cycle, then thread 2, and so on)? I’m not sure if “cycle” is the right term here, but I hope that explains what I mean.

IDK, use a different namespace

I dont think i can do that in python, but also they still both need to access the same variable, so that doesnt really help

I’d check to see if the Vex Python API provides access to a mutex (or lock) which can be used to implement thread safety.

2 Likes

micropython uses GIL.

4 Likes