My	client	wanted	their	apps	synced,	
and	I	made	it	with	Go
@torufurukawa	
Toru	Furukawa
Can	you	run	apps	in	parallel?
	
Yes,	I	guess
I	will	send	purchase	order.
Solver	simulates	only	1	Object
Solver	
(app/DLL)
Wrapper	app
SimulaMng	mulMple	objects	serially
Solver
ControlWrapper Wrapper
Swaps	internal	variables
Want	to	run	them		
in	parallel	and	synced
ControlWrapper Wrapper
Wrapper
Wrapper
(concurrent)
Concurrency?	Sync?	Go!
hOps://talks.golang.org/2012/waza.slide#14
•  Concurrency	
•  Messaging	(data	exchange)	
•  SynchronizaMon
Process
Lib	memory
DLL	simulates	an	object's	behavior
DLL
Load
Delegate	simulaMon	to	DLL	func
dll,	err	:=	syscall.LoadDLL(path)	
proc	:=	dll.MustFindProc("simulate")	
...	
for	{	
		ret,	_,	err	:=	proc.Call(...)	
		ret	!=	0{	
				break	
		}	
}
Make	another	DLL	to	call	solver	DLL
wrap_f(double	*x)	{	
		*x	=	f();	
}	
Go	app
Wrapper	DLL	
wrap_f()
Solver	DLL	
f()
Process
Lib	
memory
	Concurrency
Process
Lib	
memory
DLL	file
Load
Process
Lib	
memory
Add	message	broker
Process Process Process
Message	Broker
Listen,	Accept	and	Handle
func	main()	{	
		...	
		ch	:=	make(chan	event)	
		go	listenAndServe(ch,	...)	
		...	
}
Listen,	Accept	and	Handle
func	listenAndServe(chan	event)	{	
		ln,	err	:=	net.Listen(…)	
		for	{	
				conn,	err	:=	ln.Accept()	
				go	handleConn(conn,	ch)	
		}	
}
Handle	Requests
func	handleConn(...)	{	
		for	{	
				req	:=	read(conn)	
				respCh	:=	make(chan	…)	
				ch	<-	event{req,	
																respCh}	
				resp	:=	<-	respCh	
				write(conn,	resp)	
		}	
}
func	main()	{	
		…	
			
for	{	
				e	:=	<-	ch	
				result	=	do(e.req)	
				e.respCh	<-	result	
		}	
}
Messaging
Process Process Process
Message	Broker
SET SET SET GET
Need	all	processes	synced
Process	A
Time
Process	B
Process	C
Suspend	task	if	not	ready
func	main()	{	
		...	
		for	{	
				event	:=	<-	ch	
				if	!ready(event.req)	{	
								tasks	=	append(tasks,		
																							func()	{do(event.req)})	
								continue	
				}	
				result	=	do(event.req)			
				...	
}
Flush	tasks	when	ready
func	main()	{	
		...	
		if	readyToFlush(...)	{	
				for	_,	t	:=	range	tasks	{	
						t()	
				}	
				tasks	:=	make([]task,	0)	
		}	
		...	
}
Sync
Process	A
Time
Process	B
Process	C
Concurrency?	Sync?	Go!
Just	shipped	last	week
@torufurukawa

My client wanted their apps synced, and I made it with Go