I think it would be a good idea to externalize that multi-WaitNeeded in a separate function in the compiler, and then call that function.

Declare the following function in the functor `RunTime.oz`, for example [here](https://github.com/mozart/mozart2/blob/master/lib/compiler/RunTime.oz#L94):
```oz
proc {RecordWaitNeededFirst Rec}
   NeededWatch
in
   {Record.forAll Rec
    proc {$ Val}
       thread
          {WaitNeeded Val}
          NeededWatch = unit
       end
    end}
   {Wait NeededWatch}
end
```
and register it in in the `ProcValues0` record under the name `Record.waitNeededFirst`, for example.

Then you can simply generate the following code to call that procedure in your code generator (I mean, at the position of this line note):
```
{RecordWaitNeededFirst Result}
```
'But, will you ask, how can I make the generated code call that procedure defined in the compiler!?'
Well, like they do [here](https://github.com/mozart/mozart2/blob/master/lib/compiler/ForLoop.oz#L213-L215), i.e., with an `fOpApply` (well, `fOpApplyStatement` in this case):
```
fOpApplyStatement('Record.waitNeededFirst' [Result] unit)
```
This actually embeds the procedure `RecordWaitNeededFirst` as a *constant* in the generated code. How cool is that?