06-06-2007 08:05 AM
06-07-2007 08:30 AM
06-07-2007 09:36 AM
06-07-2007 10:21 AM
06-07-2007 10:43 AM
Ok Jonathan,
Thinking at your sample code, try to put in your 'dotnet' method a loop writing out a simple string.
Executing the two threads in parallel time, it shuld be execute interlived (you know what I mean).
Is it true?
My test code in 'managed' method is:
int MyClass::TestMethod (void) {
Random^ Rand =
gcnew Random; int iUnicID = Rand->Next(1000); // for identify the thread for (iCnt=0; iCnt < 10; iCnt++) {Thread::Sleep(1000);
printf,
"StdClass::iGetInterfaceId [%d]", iUnicID);Console::WriteLine(
"StdClass::iGetInterfaceId {0}", iUnicID);}
}
I saw the serial execution of the methods via the number random generated for single thread.
Thanx a lot for your time!
Fabrizio
06-07-2007 12:31 PM
06-08-2007 02:52 AM
06-08-2007 06:01 PM - edited 06-08-2007 06:01 PM
Hi Fabrizio,
Thanks for posting that example as it does show the behavior you were talking
about. At this point I'm not really sure why the methods are executing serially
so I'm going to have to look into this some more. Just to clarify an earlier
statement you made, calling these methods from threads in .NET showed parallel execution
right?
I'll keep you posted on what I find.
Thanks
Best Regards,
Message Edited by Jonathan N on 06-08-2007 06:02 PM
06-11-2007 05:49 AM
06-12-2007 10:47 AM
Hi Fabrizio,
The reason that you are seeing serial behavior is because the .NET library is
made thread-safe at the library level. Therefore each method invocation happens
serially. Essentially, there is one lock for all .NET library functions.
I must have had a brain freeze or something as I totally forgot about this.
Best Regards,