<join>, <notify>, <sleep>, <synchronized>, <wait>

These all should be familiar to Java programmers, and function in a similar manner. A few of these have already appeared in previous examples. Here is a fuller version of parallel-block which makes use of these; note also the <define> and <call> tasks.

Examples

<ogrescript>
	<define procedure="computeTP" ARG_x0="double" ARG_y0="double" RET_t="double" RET_p="double">
		<assign name="RET_t" double="$E{sin ( ${ARG_x0} ) - cos ( ${ARG_y0} )}"/>
		<assign name="RET_p" double="$E{cos ( ${ARG_x0} ) - sin ( ${ARG_y0} )}"/>
	</define>

	<declare name="t" double="$E{pi}"/>
	<declare name="p" double="$E{e}"/>
	<declare name="monitor" configured="true"><new-object/></declare>
	<declare name="flag" string="FREE"/>
	<sleep time="4000"/>
	
	<parallel-block idPrefix="compute" copies="10" join="true">
		<synchronized taskName="sync1-${pTaskId}" on="${monitor}">
			<while condition="$E{true}">
				<if>
                                        <equals first="${flag}" second="LOCKED"/>
					<wait on="${monitor}" timeout="5000"/>
					<else><break/></else>
				</if>
			</while>
			<assign name="flag" string="LOCKED"/>
		</synchronized>
		<call procedure="computeTP" ARG_x0="${t}" ARG_y0="${p}" RET_t="t" RET_p="p"/>
		<assign name="t-${pTaskId}" double="${t}" global="true"/>
		<echo message="t-${pTaskId} = ${t-${pTaskId}}"/>
		<synchronized taskName="sync2-${pTaskId}" on="${monitor}">
			<assign name="flag" string="FREE"/>	
			<notify on="${monitor}" all="true"/>
		</synchronized>
	</parallel-block>
</ogrescript>
  • No labels