1

Simply put, I want to manipulate two motors in parallel, then when both are ready, continue with a 3rd thread.

Below is image of what I have now. In two top threads, it sets motors B and C to "unlimited", then waits until both trigger the switches, then sets a separate boolean variable for both.

Then in 3rd thread, I poll these two variables with 1 second interval, until AND operation gives true to the loop termination condition.

3 threads

This is embedded system and all, so it may be ok here, but in "PC programming", this kind of polling loop would be rather horrible thing to do.

Question: Can I do either of both of

  • wait for variable without this kind of polling loop?
  • wait for a thread to finish without using a variable at all?
hyde
  • 60,639
  • 21
  • 115
  • 176

1 Answers1

0

Your question is a bit vague on what you actually want to achieve and using which language. As I understood you want to be able to implement a similar multithreaded motor control mechanism in Labview?

If so, then the answer to both of your questions is yes, you can implement the wait without an explicitly defined variable (other than the error cluster, which you probably would be passing around anyway). The easiest method is to pass an error cluster to both your loops and then use Merge errors to combine the generated errors once the loops are finished. Merge errors will wait until both inputs have data, merges the errors, and passes the merged error cluster on. By wiring the merged error cluster to your teardown function you effectively achieve the thread synchronization you described. If you require thread synchronization for the two control loops, you would however still have to use semaphores, rendezvous', notifiers, and other built-in synch methods.

Very simple thread synchronization

In the image there's an init function that opens two serial devices (purple wire) and passes them to the control loops, which both runs until an error (yellow-black wire) occurs. The errors from both are merged and passed to the teardown function that releases the serial devices. Notice that in this particular example the synchronization would occur at the end of program as long as there's at least one wire coming from each loop to the teardown function.

Similar functionality in a text based programming language would necessitate the use of more elaborate mechanisms, though some specialised language for parallel programming might help here.

lindblandro
  • 369
  • 2
  • 6
  • Thanks for the answer. Unfortunately the Mindstorms NXT IDE does not seem to have that (I'll double check later), but that looks exactly like I'd want a working solution to look like. To clarify, the question is not about "normal" LabVIEW, edited it a bit to make that more clear. – hyde Mar 15 '14 at 11:15
  • Ah, well, you can probably still use this approach: just pass a wire from both worker loops to the final loop. – lindblandro Mar 16 '14 at 09:05