<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">60086</assigned-user-id>
  <attachments-count type="integer">3</attachments-count>
  <closed type="boolean">false</closed>
  <created-at type="datetime">2009-07-29T07:58:49-07:00</created-at>
  <creator-id type="integer">2171</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer" nil="true"></milestone-id>
  <number type="integer">46</number>
  <permalink>ruby-thread-problems</permalink>
  <priority type="integer">123121</priority>
  <project-id type="integer">25719</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>new</state>
  <tag>ruby</tag>
  <title>Ruby Thread problems</title>
  <updated-at type="datetime">2009-08-30T11:50:03-07:00</updated-at>
  <user-id type="integer">2171</user-id>
  <user-name>Alex MacCaw</user-name>
  <creator-name>Alex MacCaw</creator-name>
  <assigned-user-name>Martin Robinson</assigned-user-name>
  <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
  <original-body>Calls to net/http are blocking (and never returning) if they're inside a thread.

In the following code, the call to open never returns.

@@@ ruby
require 'open-uri'

puts &quot;Creating thread&quot;
Thread.new do
  puts &quot;Calling net/http in thread&quot;
  puts open('http://google.com').read
  puts &quot;Should get called&quot;
end
@@@

If you run the code normally outside Titanium it works as expected.

I have a feeling the problem may be that the main thread is being used up.
irb has similar behavior to Titanium in that regard.</original-body>
  <latest-body>Calls to net/http are blocking (and never returning) if they're inside a thread.

In the following code, the call to open never returns.

@@@ ruby
require 'open-uri'

puts &quot;Creating thread&quot;
Thread.new do
  puts &quot;Calling net/http in thread&quot;
  puts open('http://google.com').read
  puts &quot;Should get called&quot;
end
@@@

If you run the code normally outside Titanium it works as expected.

I have a feeling the problem may be that the main thread is being used up.
irb has similar behavior to Titanium in that regard.</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;Calls to net/http are blocking (and never returning) if they're
inside a thread.&lt;/p&gt;
&lt;p&gt;In the following code, the call to open never returns.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
require 'open-uri'

puts &amp;quot;Creating thread&amp;quot;
Thread.new do
  puts &amp;quot;Calling net/http in thread&amp;quot;
  puts open('http://google.com').read
  puts &amp;quot;Should get called&amp;quot;
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you run the code normally outside Titanium it works as
expected.&lt;/p&gt;
&lt;p&gt;I have a feeling the problem may be that the main thread is
being used up. irb has similar behavior to Titanium in that
regard.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer">47924</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Calls to net/http are blocking (and never returning) if they're inside a thread.

In the following code, the call to open never returns.

@@@ ruby
require 'open-uri'

puts &quot;Creating thread&quot;
Thread.new do
  puts &quot;Calling net/http in thread&quot;
  puts open('http://google.com').read
  puts &quot;Should get called&quot;
end
@@@

If you run the code normally outside Titanium it works as expected.

I have a feeling the problem may be that the main thread is being used up.
irb has similar behavior to Titanium in that regard.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Calls to net/http are blocking (and never returning) if they're
inside a thread.&lt;/p&gt;
&lt;p&gt;In the following code, the call to open never returns.&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;ruby&quot;&gt;require 'open-uri'

puts &quot;Creating thread&quot;
Thread.new do
  puts &quot;Calling net/http in thread&quot;
  puts open('http://google.com').read
  puts &quot;Should get called&quot;
end&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;If you run the code normally outside Titanium it works as
expected.&lt;/p&gt;
&lt;p&gt;I have a feeling the problem may be that the main thread is
being used up.&lt;br&gt;
irb has similar behavior to Titanium in that regard.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-13T04:16:17-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-13T04:16:18-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Marshall Culpepper</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body></body>
      <body-html></body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-18T18:36:04-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- 
:assigned_user: 47924
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-18T18:36:08-07:00</updated-at>
      <user-id type="integer">60086</user-id>
      <user-name>Martin Robinson</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>I've done a bit more work with this.

It looks like when you interact with Ruby (i.e. call out to it) - the thread gets run a bit, then re-suspended.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I've done a bit more work with this.&lt;/p&gt;
&lt;p&gt;It looks like when you interact with Ruby (i.e. call out to it)
- the thread gets run a bit, then re-suspended.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-21T03:38:17-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-21T03:38:17-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>There are some relevant comments on this page:
http://aeditor.rubyforge.org/ruby_cplusplus/index.html#id2937596

Basically, it looks like Ruby embedded+Thread does not jive at all with C/C++. The workaround is to use:

&lt;pre&gt;&lt;code&gt;
fork do
 # your code here
end
&lt;/code&gt;&lt;/pre&gt;</body>
      <body-html>&lt;div&gt;&lt;p&gt;There are some relevant comments on this page:&lt;br&gt;
&lt;a href=
&quot;http://aeditor.rubyforge.org/ruby_cplusplus/index.html#id2937596&quot;&gt;http://aeditor.rubyforge.org/ruby_cplusplus/index.html#id2937596&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Basically, it looks like Ruby embedded+Thread does not jive at
all with C/C++. The workaround is to use:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
fork do
 # your code here
end&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-24T15:56:46-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-24T15:57:09-07:00</updated-at>
      <user-id type="integer">47924</user-id>
      <user-name>Marshall Culpepper</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Ok, if we're going down the fork road, we also have to work out how
to get the processes talking to each other. Names pipes aren't cross platform, and DRB is ugly for this kind of thing.


I think we should upgrade to ruby 1.9 which uses native threads - this is much more similar to the way Python does it and should work:

http://www.infoq.com/news/2007/05/ruby-threading-futures</body>
      <body-html>&lt;div&gt;&lt;p&gt;Ok, if we're going down the fork road, we also have to work out
how&lt;br&gt;
to get the processes talking to each other. Names pipes aren't
cross platform, and DRB is ugly for this kind of thing.&lt;/p&gt;
&lt;p&gt;I think we should upgrade to ruby 1.9 which uses native threads
- this is much more similar to the way Python does it and should
work:&lt;/p&gt;
&lt;p&gt;&lt;a href=
&quot;http://www.infoq.com/news/2007/05/ruby-threading-futures&quot;&gt;http://www.infoq.com/news/2007/05/ruby-threading-futures&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-25T01:24:16-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-25T01:24:18-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Ok, so I've ported Titanium to Ruby 1.9 - there are a few issues with require, but apart
from that, everything seems to worked.

Here's how I build Ruby 1.9

./configure --enable-shared --enable-pthread --prefix=/usr/local --program-suffix=19

I've attached the patch.

However, the bad news is that the thread issue remains - we're going to have to look at booting up a separate processes (like BrowserPlus does)</body>
      <body-html>&lt;div&gt;&lt;p&gt;Ok, so I've ported Titanium to Ruby 1.9 - there are a few issues
with require, but apart&lt;br&gt;
from that, everything seems to worked.&lt;/p&gt;
&lt;p&gt;Here's how I build Ruby 1.9&lt;/p&gt;
&lt;p&gt;./configure --enable-shared --enable-pthread --prefix=/usr/local
--program-suffix=19&lt;/p&gt;
&lt;p&gt;I've attached the patch.&lt;/p&gt;
&lt;p&gt;However, the bad news is that the thread issue remains - we're
going to have to look at booting up a separate processes (like
BrowserPlus does)&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T03:24:03-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T03:24:04-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Ok, so I've been doing a bit more thinking on the subject - forked processes isn't going to work.

Reason being the parent process will have to listen out on the stdout of the child process, which will block. 

Ok, so another plan. Put Ruby in a separate C++ thread, and make sure any calls going to/from Ruby are executed in the main thread.
Will that work?

How does Python get round this? Has anyone tried Threads in Python?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Ok, so I've been doing a bit more thinking on the subject -
forked processes isn't going to work.&lt;/p&gt;
&lt;p&gt;Reason being the parent process will have to listen out on the
stdout of the child process, which will block.&lt;/p&gt;
&lt;p&gt;Ok, so another plan. Put Ruby in a separate C++ thread, and make
sure any calls going to/from Ruby are executed in the main
thread.&lt;br&gt;
Will that work?&lt;/p&gt;
&lt;p&gt;How does Python get round this? Has anyone tried Threads in
Python?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T07:34:14-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T07:34:21-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Python uses native threads underneath, so things are fine as long as you surround non-Python with a special call to Python signaling that other threads can run. When you need to call Python functions or execute Python code, you must first obtain the GIL and then run your code.

Does Ruby have a similar mechanism?</body>
      <body-html>&lt;div&gt;&lt;p&gt;Python uses native threads underneath, so things are fine as
long as you surround non-Python with a special call to Python
signaling that other threads can run. When you need to call Python
functions or execute Python code, you must first obtain the GIL and
then run your code.&lt;/p&gt;
&lt;p&gt;Does Ruby have a similar mechanism?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T07:58:49-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T07:59:13-07:00</updated-at>
      <user-id type="integer">60086</user-id>
      <user-name>Martin Robinson</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Found this, does it help?

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10252</body>
      <body-html>&lt;div&gt;&lt;p&gt;Found this, does it help?&lt;/p&gt;
&lt;p&gt;&lt;a href=
&quot;http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10252&quot;&gt;
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/10252&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T08:10:42-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T08:10:43-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>This is one half of the equation. The second half is what he alludes to with this
&lt;blockquote&gt;
You can't call Ruby's method from solve_difficult_numerical_problem().  I'll prepare API to support this.
&lt;/blockquote&gt;

If that's available we should have everything we need.</body>
      <body-html>&lt;div&gt;&lt;p&gt;This is one half of the equation. The second half is what he
alludes to with this&lt;br&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;br&gt;
You can't call Ruby's method from
solve_difficult_numerical_problem(). I'll prepare API to support
this.&lt;br&gt;&lt;/blockquote&gt;
&lt;p&gt;If that's available we should have everything we need.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T08:36:59-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T08:37:01-07:00</updated-at>
      <user-id type="integer">60086</user-id>
      <user-name>Martin Robinson</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Found this which may also help:

/*
 * rb_thread_call_with_gvl - re-enter into Ruby world while releasing GVL.
 *
 ***
 *** This API is EXPERIMENTAL!
 *** We do not guarantee that this API remains in ruby 1.9.2 or later.
 ***
 *
 * While releasing GVL using rb_thread_blocking_region() or
 * rb_thread_call_without_gvl(), you can not access Ruby values or invoke methods.
 * If you need to access it, you must use this function rb_thread_call_with_gvl().
 *
 * This function rb_thread_call_with_gvl() does:
 * (1) acquire GVL.
 * (2) call passed function `func'.
 * (3) release GVL.
 * (4) return a value which is returned at (2).
 *
 * NOTE: You should not return Ruby object at (2) because such Object
 *       will not marked.
 *
 * NOTE: If an exception is raised in `func', this function &quot;DOES NOT&quot;
 *       protect (catch) the exception.  If you have any resources
 *       which should free before throwing exception, you need use
 *       rb_protect() in `func' and return a value which represents
 *       exception is raised.
 *
 * NOTE: This functions should not be called by a thread which
 *       is not created as Ruby thread (created by Thread.new or so).
 *       In other words, this function *DOES NOT* associate
 *       NON-Ruby thread to Ruby thread.
 */
void *
rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
{</body>
      <body-html>&lt;div&gt;&lt;p&gt;Found this which may also help:&lt;/p&gt;
&lt;p&gt;/* * rb_thread_call_with_gvl - re-enter into Ruby world while
releasing GVL. *&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;This API is EXPERIMENTAL!&lt;/em&gt;&lt;/strong&gt; We do not
guarantee that this API remains in ruby 1.9.2 or later.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;* * While releasing GVL using rb_thread_blocking_region() or *
rb_thread_call_without_gvl(), you can not access Ruby values or
invoke methods. * If you need to access it, you must use this
function rb_thread_call_with_gvl(). * * This function
rb_thread_call_with_gvl() does: * (1) acquire GVL. * (2) call
passed function &lt;code&gt;func'. * (3) release GVL. * (4) return a
value which is returned at (2). * * NOTE: You should not return
Ruby object at (2) because such Object * will not marked. * * NOTE:
If an exception is raised in&lt;/code&gt;func', this function &quot;DOES NOT&quot;
* protect (catch) the exception. If you have any resources * which
should free before throwing exception, you need use * rb_protect()
in &lt;code&gt;func' and return a value which represents * exception is
raised. * * NOTE: This functions should not be called by a thread
which * is not created as Ruby thread (created by Thread.new or
so). * In other words, this function *DOES NOT* associate *
NON-Ruby thread to Ruby thread. */ void *&amp;lt;br/&amp;gt;
rb\_thread\_call\_with\_gvl(void *(*func)(void *), void
*data1)&amp;lt;br/&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T08:40:04-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T08:40:10-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Let me try the formatting again:

@@@ text

/*
 * rb_thread_call_with_gvl - re-enter into Ruby world while releasing GVL.
 *
 ***
 *** This API is EXPERIMENTAL!
 *** We do not guarantee that this API remains in ruby 1.9.2 or later.
 ***
 *
 * While releasing GVL using rb_thread_blocking_region() or
 * rb_thread_call_without_gvl(), you can not access Ruby values or invoke methods.
 * If you need to access it, you must use this function rb_thread_call_with_gvl().
 *
 * This function rb_thread_call_with_gvl() does:
 * (1) acquire GVL.
 * (2) call passed function `func'.
 * (3) release GVL.
 * (4) return a value which is returned at (2).
 *
 * NOTE: You should not return Ruby object at (2) because such Object
 *       will not marked.
 *
 * NOTE: If an exception is raised in `func', this function &quot;DOES NOT&quot;
 *       protect (catch) the exception.  If you have any resources
 *       which should free before throwing exception, you need use
 *       rb_protect() in `func' and return a value which represents
 *       exception is raised.
 *
 * NOTE: This functions should not be called by a thread which
 *       is not created as Ruby thread (created by Thread.new or so).
 *       In other words, this function *DOES NOT* associate
 *       NON-Ruby thread to Ruby thread.
 */
void *
rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
{
@@@</body>
      <body-html>&lt;div&gt;&lt;p&gt;Let me try the formatting again:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;text&quot;&gt;
/*
 * rb_thread_call_with_gvl - re-enter into Ruby world while releasing GVL.
 *
 ***
 *** This API is EXPERIMENTAL!
 *** We do not guarantee that this API remains in ruby 1.9.2 or later.
 ***
 *
 * While releasing GVL using rb_thread_blocking_region() or
 * rb_thread_call_without_gvl(), you can not access Ruby values or invoke methods.
 * If you need to access it, you must use this function rb_thread_call_with_gvl().
 *
 * This function rb_thread_call_with_gvl() does:
 * (1) acquire GVL.
 * (2) call passed function `func'.
 * (3) release GVL.
 * (4) return a value which is returned at (2).
 *
 * NOTE: You should not return Ruby object at (2) because such Object
 *       will not marked.
 *
 * NOTE: If an exception is raised in `func', this function &quot;DOES NOT&quot;
 *       protect (catch) the exception.  If you have any resources
 *       which should free before throwing exception, you need use
 *       rb_protect() in `func' and return a value which represents
 *       exception is raised.
 *
 * NOTE: This functions should not be called by a thread which
 *       is not created as Ruby thread (created by Thread.new or so).
 *       In other words, this function *DOES NOT* associate
 *       NON-Ruby thread to Ruby thread.
 */
void *
rb_thread_call_with_gvl(void *(*func)(void *), void *data1)
{&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-07-29T08:41:08-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-07-29T08:41:12-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>We should also look at Ebb:
http://github.com/ry/ebb/tree/master

http://github.com/ry/ebb/blob/d9c9c1e030ea888ebbbefb9013c726b78eaf2df6/ext/ebb_ffi.c#L91</body>
      <body-html>&lt;div&gt;&lt;p&gt;We should also look at Ebb:&lt;br&gt;
&lt;a href=
&quot;http://github.com/ry/ebb/tree/master&quot;&gt;http://github.com/ry/ebb/tree/master&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=
&quot;http://github.com/ry/ebb/blob/d9c9c1e030ea888ebbbefb9013c726b78eaf2df6/ext/ebb_ffi.c#L91&quot;&gt;
http://github.com/ry/ebb/blob/d9c9c1e030ea888ebbbefb9013c726b78eaf2...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-05T04:05:12-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-05T04:05:13-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>The BrowserPlus Ruby module is on github. http://github.com/lloyd/bp-ruby

I recommend taking a look at it, especially the following line, which allows threads to run properly (even in Ruby 1.8).

http://github.com/lloyd/bp-ruby/blob/a799343d35edec38da3f5e215ab6d27a824a3d8d/src/RubyInterpreter.cpp#L121</body>
      <body-html>&lt;div&gt;&lt;p&gt;The BrowserPlus Ruby module is on github. &lt;a href=
&quot;http://github.com/lloyd/bp-ruby&quot;&gt;http://github.com/lloyd/bp-ruby&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I recommend taking a look at it, especially the following line,
which allows threads to run properly (even in Ruby 1.8).&lt;/p&gt;
&lt;p&gt;&lt;a href=
&quot;http://github.com/lloyd/bp-ruby/blob/a799343d35edec38da3f5e215ab6d27a824a3d8d/src/RubyInterpreter.cpp#L121&quot;&gt;
http://github.com/lloyd/bp-ruby/blob/a799343d35edec38da3f5e215ab6d2...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-11T06:14:53-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-11T06:14:57-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Ok, I've solved all the issues encountered so far, here's the patch:</body>
      <body-html>&lt;div&gt;&lt;p&gt;Ok, I've solved all the issues encountered so far, here's the
patch:&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-19T14:25:00-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-19T14:25:04-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>The only things left to do is call RubyModule::Lock() and RubyModule::Unlock() whenever the Ruby C API is accessed, basically in the same places you have to lock the Python GIL.</body>
      <body-html>&lt;div&gt;&lt;p&gt;The only things left to do is call RubyModule::Lock() and
RubyModule::Unlock() whenever the Ruby C API is accessed, basically
in the same places you have to lock the Python GIL.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-19T14:28:59-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-19T14:29:03-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>I've updated the patch to Martin's directions and will upload it as soon as I can.

There are some issues with the patch as it stands. If you lock Ruby inside another thread that thread then sleeps (only the main one continues). So I think the solution is, in ruby_utils, change the methods on the class to call them in the main thread - I think there's a function already to do this, but I'll need a little help with this (probably use a macro).

I'll pop onto IRC next week (as am back then) to discuss.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I've updated the patch to Martin's directions and will upload it
as soon as I can.&lt;/p&gt;
&lt;p&gt;There are some issues with the patch as it stands. If you lock
Ruby inside another thread that thread then sleeps (only the main
one continues). So I think the solution is, in ruby_utils, change
the methods on the class to call them in the main thread - I think
there's a function already to do this, but I'll need a little help
with this (probably use a macro).&lt;/p&gt;
&lt;p&gt;I'll pop onto IRC next week (as am back then) to discuss.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-26T08:10:16-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-26T08:10:18-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">60086</assigned-user-id>
      <attachments-count type="integer">2</attachments-count>
      <body>Here's the updated patch. You can see I've created a new method 'RubyKObjectMethodMissingKroll' in ruby_utils.cpp to show
how the Thread issue could be easily solved.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Here's the updated patch. You can see I've created a new method
'RubyKObjectMethodMissingKroll' in ruby_utils.cpp to show&lt;br&gt;
how the Thread issue could be easily solved.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-08-30T02:09:59-07:00</created-at>
      <creator-id type="integer">2171</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">46</number>
      <permalink>ruby-thread-problems</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">25719</project-id>
      <state>new</state>
      <tag>ruby</tag>
      <title>Ruby Thread problems</title>
      <updated-at type="datetime">2009-08-30T11:50:03-07:00</updated-at>
      <user-id type="integer">2171</user-id>
      <user-name>Alex MacCaw</user-name>
      <creator-name>Alex MacCaw</creator-name>
      <assigned-user-name>Martin Robinson</assigned-user-name>
      <url>http://appcelerator.lighthouseapp.com/projects/25719/tickets/46</url>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>29b937aa6029367bd30184c1e4b23a28006b2c32</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-07-29T03:24:03-07:00</created-at>
      <filename>textmate_stdin_w2rQID.txt</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">231789</id>
      <size type="integer">4996</size>
      <uploader-id type="integer">2171</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://appcelerator.lighthouseapp.com/attachments/231789/textmate_stdin_w2rQID.txt</url>
    </attachment>
    <attachment type="Attachment">
      <code>34eeda81ad18e00aa43167c30befad2dfb9313ae</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-08-19T14:25:00-07:00</created-at>
      <filename>ruby_19.patch</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">248048</id>
      <size type="integer">8834</size>
      <uploader-id type="integer">2171</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://appcelerator.lighthouseapp.com/attachments/248048/ruby_19.patch</url>
    </attachment>
    <attachment type="Attachment">
      <code>05a7ed2f8f90a2b00adba5e22e85f49a5b91b889</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2009-08-30T02:09:59-07:00</created-at>
      <filename>textmate_stdin_hmVnPx.txt</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">256467</id>
      <size type="integer">4741</size>
      <uploader-id type="integer">2171</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://appcelerator.lighthouseapp.com/attachments/256467/textmate_stdin_hmVnPx.txt</url>
    </attachment>
  </attachments>
</ticket>
