From: Gin Mendi Date: 2009-09-09T12:04:02+09:00 Subject: Re: Problems with cross-thread violation Eleanor McHugh wrote: > Are you certain that in the case of no feed being available, you're > receiving a nil rather than a zero? Because if not then the following > condition will always be true and then there'll be times when you try > and access a non-existent feed. Yep handle will be nil if log_on fails or encounters an error. > > You could try installing Tenderlove's Never Say Die library from > github, it allows you to rescue segfaults which might allow you to > extract some useful program state or else continue as if nothing had > gone wrong (but that's a really bad idea in the majority of cases). > > You might also try coding your wrapper with ruby-ffi rather than ruby/ > dl. > Ok I'll try looking and studying both of those suggestions. Might take a while for me to redo with ffi but I'll post back here what the results were. You mentioned earlier that I may need a separate callback instance for each feed handle: > Does get_live_feed use a separate thread internally? If so the cross- > thread violation could well be related to garbage collection of the > callback in which case you may need a separate callback instance for > each feed handle. Sorry but I don't fully understand how I could go about doing this? How would this work? Also a little side problem I still haven't solved regarding my callback: fc = DL.callback('0PL') { |result_list, count| } if result_list result_list.struct('C16FF', :code, :value, :stat) puts result_list[:code].pack('C16') puts result_list[:value] end } you'll notice I have a count parameter which is the number of records in result_list. I assume result list is an array if count > 1. Been trying to figure out how to extract each record if count > 1. Right now only managed to do this with just one record as you can see. How could I convert my pointer to an array then get each element/record? I'm assuming result_list is an array. I tried result_list.ptr.to_a but that just made the program crash back to the command prompt with no error. Anyway thanks again for all the help! -- Posted via http://www.ruby-forum.com/.