[Haskell-cafe] How to ensure code executes in the context of a specific OS thread?

Felipe Almeida Lessa felipe.lessa at gmail.com
Mon Jul 4 15:44:36 CEST 2011


On Mon, Jul 4, 2011 at 2:38 AM, Jason Dagit <dagitj at gmail.com> wrote:
> (I believe the way the FFI works I'll have
> to make a new wrapper for each "thing" because I can't directly call
> objective-c).

Probably, yes.

> I suppose I should try adding wrappers around all the GLFW functions
> so that it sends the request over to the main thread and see if it
> solves my problem.  The downside is that it would be a lot of wrapper
> code and it would be nice to have solution that other libraries can
> use.

Do you mean, on each function of GLFW's API?  Usually it's better to
call postGUISync/postGUIAsync alikes with the largest number of
function calls possible because (a) of the overhead (especially
postGUISync's) and (b) it's safer to assume that postGUIAsyncs can be
reordered.

That is, if you need to call 'do {foo; bar}', instead of using 'do
{fooS; barS}' where these are wrapped functions, call 'postGUISync $
do {foo; bar}'.  This solution is general in the sense that you only
have to code it once for everything Cocoa-related.

Cheers! =)

-- 
Felipe.



More information about the Haskell-Cafe mailing list