spin is an experimental project and far from beeing available for commercial usage. If you are interrested in spin: mailto://spin@toem.de.

Introducing Spin 5 - Proclets

Proclets are 2nd level processes initiated within a threaded or normal process. There are two basic flavours available:

  • Synchronous Proclets
  • Asynchronous Proclets

Synchronous Proclets

Synchronous proclets are running synchronous with normal and threaded processes.

Delayed connector access

The method write(long delta,E val) allows simple signal generation with connectors of type IOut and ISource.

// 100 ns rectangle
out.write(true, Time.ns(100));
out.write(false, Time.ns(200));
Scheduled Proclets

Scheduled proclets are pieces of code that are getting executed at a defined point of time:

schedule(Time.ns(100), new IRunnable(){

	@Override
	public void run(IRunInfo info) {	
		log("Scheduled proclet");
		out.write(50);
		log(out);
	}
	
});

The code needs to be embedded in the run method of an IRunnable object.

Asynchronous Proclets

Async proclets are processes that run for a given time in parallel to normal (synchronous) processes driven by the scheduler. They are useful to parallelize and speed up computations. Async proclets can be initiated within threaded or non-threaded processes.

Normal async proclet

The asynchronous code needs to be embedded in the run method of an IAsync object. The asynchronous code must not access any ports or other non-synchronized objects and variables. The sync method is called with the given delay. Here the results of the run method can be transfered to any ports.

log("Start async proclet in normal process");
runAsync(Time.ns(200), new IAsync() {

	@Override
	public void run(IRunInfo info) {
		// doing work -- no connector access
		for (int i=0;i<1000000000;i++)
			value = value * i + 1;
	}

	@Override
	public void sync(IRunInfo info) {
		log("Finished async proclet in normal process");
		out.write(value);
		log(out);
	}
});
Sleep proclet
Sleep proclets can only be used in threaded processes. While sleeping, the code in the IAsync object is executed asynchronously.
log("Start sleep proclet in threaded process");
sleep(Time.ns(200), new IAsync() {

	@Override
	public void run(IRunInfo info) {
		// doing work -- no connector access
		for (int i=0;i<1000000000;i++)
			value = value * i + 1;
	}

	@Override
	public void sync(IRunInfo info) {	
		log("Finish sleep proclet in threaded process");
		out.write(value);							
		log(out);
	}
});
Instead of using the sync method for port access, the method can be left empty. The code to put the result into the ports can be put after the sleep method.

Output

spin 0.5.3
Copyright (c) 2011-2012 by toem
ALL RIGHTS RESERVED
-----------------------------------------------
-----------------------------------------------
No. of Modules: 3 
No. of Threads: 1 
No. of Connections: 2 
-----------------------------------------------
[00000000] Info : I5_Proclets.P2.proc   I5_Proclets.P2.out = 100
[00000000] Info : I5_Proclets.P2.proc   Start async proclet in normal process
[00000100] Info : I5_Proclets.P2.proc   Scheduled proclet
[00000100] Info : I5_Proclets.P2.proc   I5_Proclets.P2.out = 50
[00000200] Info : I5_Proclets.P2.proc   Finished async proclet in normal process
[00000200] Info : I5_Proclets.P2.proc   I5_Proclets.P2.out = -1490602308
[00001000] Info : I5_Proclets.P1.proc   I5_Proclets.P1.out = 100
[00001000] Info : I5_Proclets.P1.proc   Start sleep proclet in threaded process
[00001200] Info : I5_Proclets.P1.proc   Finish sleep proclet in threaded process
[00001200] Info : I5_Proclets.P1.proc   I5_Proclets.P1.out = -1490602308
-----------------------------------------------
Simulated  Time: 1200 [ns]
Simulation Time: 2,241000 [s]
Factor:1867500,000000
-----------------------------------------------