[Mono-list] Calls to CIL code from native threads

Patrick Hartling patrick@vrac.iastate.edu
Mon, 26 Jan 2004 15:26:00 -0600


--=-7g+G6p5Dz3gtuaF+oFZp
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

I am working on a project that mixes CIL code with natively compiled C
and C++ in a multi-threaded environment.  The natively compiled code may
make calls into the CIL universe from different threads, and I am trying
to figure out how to manage that with Mono's C API.  In the
documentation about embedding Mono, I see a reference to the function
mono_thread_attach().  My (very preliminary) testing has allowed me to
make a call from a native thread other than the primordial thread into
the CIL universe by calling mono_thread_attach() first.  I pass in a
pointer to a MonoDomain object allocated on the heap by the calling
thread via mono_domain_create().

After the call into the CIL code returns, however, I appear to get into
a deadlock state later when I make another call to
mono_thread_attach().  I have successfully dealt with a similar
situation using Python/C where the Global Interpreter Lock (GIL) must be
acquired and released to allow native code threads to call into the
Python interpreter.  I am wondering if calling mono_thread_attach() has
the effect of acquiring a mutex somewhere that needs to be released by
my code when I no longer need to hold it.  Is that the case?  If so,
what is the call to make this happen?  Or am I just on the wrong track
entirely?

Lastly, is there any documentation for doing multi-threaded programming
with Mono?  So far, I have mostly been looking through the code trying
to find types and functions that look roughly like what I need.

 -Patrick


--=20
Patrick L. Hartling                     | Research Assistant, VRAC
patrick@vrac.iastate.edu                | 2274 Howe Hall Room 2624
http://www.vrac.iastate.edu/~patrick/   | http://www.vrac.iastate.edu/
PGP: http://wwwkeys.gpg.cz:11371/pks/lookup?op=3Dget&search=3D0xEBF86398


--=-7g+G6p5Dz3gtuaF+oFZp
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQBAFYXo5DgSg+v4Y5gRAge+AJsGkdSbOI1OFcilPTh/pBkxFamSIgCfaZv5
cyR1twlHYVydsuU32hMU9aU=
=pi+2
-----END PGP SIGNATURE-----

--=-7g+G6p5Dz3gtuaF+oFZp--