From: Gin Mendi Date: 2009-09-08T13:09:26+09:00 Subject: Re: Problems with cross-thread violation Eleanor McHugh wrote: >> I'm unsure if get_live_feed uses a seperate thread. I just have the >> dll >> and no source. If get_live_feed does use a seperate thread how would I >> make a seperate feed handle? Does that mean I need to declare a new >> callback and pass that each time I call live feed? > > Not necessarily, but it's certainly an experiment I'd consider as part > of taming the problem. If you know C reasonably well I also recommend > taking a peak through /ext/dl in the Ruby sources. That's not for the > faint-hearted though. I'm only learning C now as I was trying to look at the source code. At first glance I couldn't understand anything there but I'll study it if I run out of ideas. Anything in particular that I should study? > No, it just means that while garbage collection is disabled your > unreferenced objects will remain in memory. Once you reenable it all > those dead objects will then be dealt with during the next collection > cycle, including freeing up any memory associated with DataPtr objects > you may have created with DL::malloc. what about the pointers in the callback will those remain unreferrenced or are they automatically freed when the callback ends? Well I tried disabling GC as you suggested but I got the same result. Here's what I did: require 'feed_library' module live_feed # my callback for the live feed fc = DL.callback('0PL') { |result_list, count| } if result_list record = FeedRecord.new(result_list) puts record.code end } # handle used to request for a feed handle = FeedLibrary::log_on("user", "password") if handle GC.disable session = get_live_feed(handle, fc) loop do end GC.enable end end I still got the cross-thread violation on rb_thread_schedule() I tried changing the callback. Instead of using the struct class FeedRecord I instead used the struct! method. So I made it simple just to access 3 fields from the data structure: 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 } I instead got a crash where I would see the printout of the callback with mixed in letters forming segmentation fault. Other runs would just flat out crash back to the command prompt. -- Posted via http://www.ruby-forum.com/.