B
Boris
Hi,
Background: Let's say, there's a DLL - A.DLL (native code) that exports
function Foo(). Foo() calls some C-runtime library functions. Some other
native code (for example, in an EXE) calls Foo() from multiple threads.
There're 2 requirements to prevent multi-threading related problems inside
CRT:
1. A.DLL should be built using multi-threaded version of CRT;
2. Threads that call Foo() must be started via _beginthread/_beginthreadex,
but not via CreateThread().
I have a question on calling Foo() inside A.DLL from C# code: would calling
CRT functions by Foo() be still thread safe, if A.DLL was compiled/linked
with multi-threaded version of CRT and the below C# caller code was used?
public class SomeClass
{
...
[System.Runtime.InteropServices.DllImport("A.DLL")]
public static extern void Foo();
...
private void MyThreadFunc()
{
Foo();
}
private Thread m_thread;
...
static void Main()
{
...
m_thread = new Thread(new ThreadStart(this.MyThreadFunc));
...
}
}
Thanks,
Boris
Background: Let's say, there's a DLL - A.DLL (native code) that exports
function Foo(). Foo() calls some C-runtime library functions. Some other
native code (for example, in an EXE) calls Foo() from multiple threads.
There're 2 requirements to prevent multi-threading related problems inside
CRT:
1. A.DLL should be built using multi-threaded version of CRT;
2. Threads that call Foo() must be started via _beginthread/_beginthreadex,
but not via CreateThread().
I have a question on calling Foo() inside A.DLL from C# code: would calling
CRT functions by Foo() be still thread safe, if A.DLL was compiled/linked
with multi-threaded version of CRT and the below C# caller code was used?
public class SomeClass
{
...
[System.Runtime.InteropServices.DllImport("A.DLL")]
public static extern void Foo();
...
private void MyThreadFunc()
{
Foo();
}
private Thread m_thread;
...
static void Main()
{
...
m_thread = new Thread(new ThreadStart(this.MyThreadFunc));
...
}
}
Thanks,
Boris