From: Robert Klemme Date: 2013-04-08T17:37:13+09:00 Subject: Re: Mapping string data ptr to buffer in ffi --000e0cd6b43cb0a31b04d9d557df Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 8, 2013 at 4:06 AM, se gm wrote: > I'm trying to implement some "shared memory" in Ruby, but I'm not sure > how to declare it properly with ffi. The idea is to map the read-only > (in Ruby) string contents(by passing a data ptr) to external C library > threads so that they would write some data to it. Could you point out > the proper way to do it ? > I think a better way would be to implement a Ruby class in C and provide the information via a getter method which returns a new Ruby String and internally uses proper synchronization to maintain thread safety. Otherwise if you update the String contents from arbitrary threads you will create all sorts of race conditions and issues which are hard to hunt down. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --000e0cd6b43cb0a31b04d9d557df Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Apr 8, 2013 at 4:06 AM, se gm <lists@ruby-forum.com= > wrote:
I'm trying to implement some "share= d memory" in Ruby, but I'm not sure
how to declare it properly with ffi. The idea is to map the read-only
(in Ruby) string contents(by passing a data ptr) to external C library
threads so that they would write some data to it. Could you point out
the proper way to do it ?=A0

I think a better way would be to implement a Ruby class in C a= nd provide the information via a getter method which returns a new Ruby Str= ing and internally uses proper synchronization to maintain thread safety. = =A0Otherwise if you update the String contents from arbitrary threads you w= ill create all sorts of race conditions and issues which are hard to hunt d= own.

Kind regards

robert

--
remember.guy do |a= s, often| as.you_can - without end
http://blog.rubybestpractices.com/
--000e0cd6b43cb0a31b04d9d557df--