runtime.LockOSThread is useful if you need all calls
to an API to originate in a single thread. This is necessary
for some brain-dead APIs like SDL and NaCl and ptrace
that maintain hidden internal per-thread state.
That doesn't sound like the problem here.
I would start by just introducing a top level
var l sync.Mutex
and then around each call into cairo do
l.Lock()
... cairo stuff ...
l.Unlock()
and see if that fixes the problem. That will make
only one goroutine at a time be able to call into cairo,
which is very likely to keep it from crashing, at the cost
of not having any parallelism. Assuming that fixes the
problem, then you could start removing the locking one
call site at a time and see when things begin to break again.
Russ
it sounds like you want runtime.LockOSThread.
after a goroutine has called LockOSThread, it is
guaranteed that that goroutine will always execute
in that thread, and no other goroutine will.
russ
On 15 December 2010 13:30, Philippe Leroux
a complete example would be better (reduced
as much as you can).
for instance, it's not clear exactly where you're
calling cairo.