Title: multiple results in multiple places Post by: GeorgeK on September 21, 2010, 01:08:32 AM I have code
RtcClientModule1.Prepare('MyFunction'); RtcClientModule1.Execute; MyResult := RtcClientModule1.LastResult.AsString; My problem is that this code may be executed from different places at the same time, so LastResult may conflict. Is it safe to change it to: RtcClientModule1.Prepare('MyFunction'); with RtcClientModule1.Execute do MyResult := AsString; to avoid conflict between different "Executes" inside app? Title: Re: multiple results in multiple places Post by: D.Tkalcec (RTC) on September 21, 2010, 01:13:43 AM You can't use one blocking socket component from multiple threads at the same time. That's like trying to read and write to and from the same complex object from multiple threads at the same time which is a big no-no.
If you want to make remote calls on the Client from multiple threads at the same time, you will either need to do it non-blocking and implement events, or you will need a separate TRtcClientModule component per thread. Best Regards, Danijel Tkalcec Title: Re: multiple results in multiple places Post by: GeorgeK on September 21, 2010, 10:25:05 AM well, what I mean when I have two or more functions (different) and they will be called at the same time.
for example I have HelloWorld function and HelloPeople. If server execute both remote functions at the same time, what happens? Title: Re: multiple results in multiple places Post by: D.Tkalcec (RTC) on September 21, 2010, 11:58:34 AM If you set MultiThreaded to TRUE on the TRtcHttpServer component and functions are called using different connection components (for example, from multiple clients or from the same client using multiple TRtcHttpClient components), then both functions will be executed at the same time. There is nothing special you need to do on either Client nor Server except making sure that your own code in the Server is thread-safe (for example, do not use a single global database connection component, but use a database connection pool or create and destroy components inside RTC events).
On the other hand, if you set MultiThreaded to FALSE on the TRtcHttpServer component, no matter how many clients call the Server at the same time all the calls will be executed one after another (serialized). In this case, your server-side code does not need to be thread-safe because there will always be only one thread running and there will be no concurrent access to your own Server-side code. Best Regards, Danijel Tkalcec |