> Thanks for your reply Mario, could you please point me in the direction
> of the documentation for background thread input logging?
it's happening automatically -- that's where GetChar, etc are storing keypresses until you ask for them. it uses java's concurrency, i guess another option for you if that's more your thing than c.
> I don't think that the existence
> of work-arounds should stifle conversation about perhaps more ideal
> solutions.
emitting a ttl timed exactly with the flips is such a coupled task that using concurrency just for that is way overcomplicating. concurrency is extremely hairy to get right and only now are the most modern languages (haskell) discovering abstractions that improve code safety and simplicity/readability in a concurrent context. if the workers don't need to interact, the problems go away, but as soon as you have to coordinate them, you have to be extremely careful about deadlock, not overwriting information in one task during the time that some other task is depending on that information not changing, etc.
as mario said, in your case, the flipping process has to tell the trigger process each time it flips, so you haven't saved anything from just triggering in the flipping process!
the times i wish i had concurrency are things like opening a reward valve for a timed duration while still showing stimuli, etc. that's a case where two different kinds of state gets all unpleasantly jumbled in the drawing loop. checking for responses and their correctness is another example, or playing a sound just when a beambreak is blocked, or keeping a log of mouse movements, etc.
> spmd
http://en.wikipedia.org/wiki/Referential_transparency_(computer_science)
as you discovered, they put all sorts of limitations on spmd code, i believe in an effort to prevent you from running into the types of problems described above. the "transparency" they describe looks like a typical mathworks-mangling of something that would have been useful if done correctly, in this case "referential transparency," which means "calling this function doesn't have any side-effects, all it does is compute a value, and given the same arguments, that value is guaranteed to be the same. so it is guaranteed not to do things like look up web pages, read from a random number generator, etc." those are all side effects that would make a visible change out in the real world.
just an aside, in haskell, code is pure (referentially transparent) by default. you sequester side effecting code, so it can't infect everything -- this is enforced by the compiler! pure code can be automatically parallelized! often people make the distinction between 'parallel' and 'concurrent' -- parallel being just those cases where the workers are pure, so you don't have the usual thorny coordination problems, a compiler can safely apply very dramatic optimizations, etc.
side effects, though, can be used by workers to communicate arbitrarily, opening up all the problems.
back to spmd, it looks like they were only halfhearted about trying to prevent side effects -- they say you can't 'save', but it looks like you found fopen/fprintf worked.
http://www.mathworks.com/help/distcomp/programming-tips_brukbnp-9.html#brukbnp-12
i don't see them saying you can't call java objects or mex functions, but if they let you call them, there's a huge hole letting you have arbitrary side effects. if you opened a ptb window, you got a mex call working, so if you insisted, you could use this to work around their attempts to stop you. same for writing to a file, writing to the network (or screen), etc.
but you are really forcing a square peg into a round hole here. note spmd = "single program multiple data" -- it is meant to work on very regular problems, like applying the same transformation at every point in an array or something -- exactly like the vectorized simd functions we all know and love -- fft, sum, etc, that run on a chip designed to do the same thing to several datapoints all at once, not as a loop on the cpu working one at a time. note how your program was really three different programs.
the toolbox gives you 'batch' for this:
http://www.mathworks.com/help/distcomp/batch.html
and i don't see that it limits what you can do in each worker, so it looks like you can go nuts running into nondeterministic concurrency bugs. :)
> Additionally, I can see parfor loops having some utility in video
> preloading, although I haven't given it a go myself.
not sure what you mean by preloading (computing a complicated stimulus offline? sure. but reading a huge stimulus from disk? won't help.), but parfor requires the workers to be both pure and independent, so it wouldn't work for the concurrency we've been discussing.
http://www.mathworks.com/help/distcomp/getting-started-with-parfor.html#brdqg4q-1
-e