...
Physically, each ETS node will introduce a thread. Thus, the intersection operator must synchronize the upstream input threads in order to generate the correct result. In order to have a pipeline operation, the intersection is implemented in a sort-merge manner. Therefore, each input is required to be sorted. The synchronization is handled by the thread of input No.0, which means the thread 0 will call the writer.open/nextFrame/close functions. If we authorize arbitrary threads to push forward, the downstream operator will be confused, especially in synchronizing their locks. The core logical intersection function is as below:
- do
- find the max input: maxinput id of the maximum record
- for each input i
- if record < max keep popping
- if record == max keep popping until it matches max. then match++; continue
- if > max, break
- If match == inputArity
- output max record
- while no input is closed.
...