Hi,

On Wed, Sep 14, 2011 at 1:46 PM, Marmaduke Woodman <[email protected]> wrote:
> A quick solution that might work is to have a member in the struct 'locked'
> that you set to true before the factor writes and set to false when it has
> finished. Then in c, write the equivalent of
>
> While (not struct.locked)  { }
>
> Before you read from the struct.
>
> Because your read/write pattern is simple, this could work fine. In more
> complicated situations, locks can cause a lot of headaches.

This sounds fragile and potentially wrong. Also, spinning wastes CPU time.

If you run Factor in one thread and your C code in another, then you
should be able to just use pthread mutexes. Use the Factor FFI to bind
to the pthread API, and put a lock inside your struct. Take the lock
when you modify it.

Cheers,

Slava

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to