From: MenTaLguY Date: 2009-07-26T09:01:17+09:00 Subject: Re: C extension and Ruby threads --=-3UfJ6Gds8EeaNh7ZUmt4 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sun, 2009-07-26 at 07:18 +0900, John Bob wrote: > - I created a ruby class Client that inherits from BaseClient. In the > constructor of this class, I create a thread that loops on the method > receive(). Note that in my C code, the receive function does a > WaitForSingleObject (Windows equivalent of pthread_cond_wait ) with a > timeout of 100ms In 1.8, there's not really a good way to address this unless you can convert the object you're waiting on to a file descriptor suitable to wait on with rb_thread_select(). In 1.9, there is additionally an API function -- rb_thread_blocking_region -- which you can use to wrap a function which needs to block (provided that the function doesn't touch the Ruby interpreter or Ruby objects in any way); rb_thread_blocking_region permits other threads to continue while the function you pass to it blocks. Either approach should also permit you to simply block without polling with a timeout as you do now. -mental --=-3UfJ6Gds8EeaNh7ZUmt4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkprnCcACgkQEpMFVe94r24OZgCdHxD2vcl9ZzOdHPyTg9c2EyU7 FkMAn0+Y8zG8k0YQNVX3i1ryyKfSvXia =vEDu -----END PGP SIGNATURE----- --=-3UfJ6Gds8EeaNh7ZUmt4--