ThreadSafe activation or not ?

Zugg

Member²
Hello,

I'm working with DOA 4.1.2 in Delphi 2009 with Oracle 10gR2 (10.2.0.1.0) or Oracle 11gR2 (11.2.0.1).

In order to not block my application, when I open a huge dataset, I'll do the TOracleDataSet.open in a thread:
- Main thread start another thread
- Main thread wait the end of this thread
- the thread open the dataset and display data in a dbgrid

In Oracle 10.2.0.1.0, when I execute the open everything works perfectly.
In Oracle 11.2.0.1.0, sometimes there is external exception: External exception EBADBB81. When I remove the thread, TOracleDataSet.open works perfectly.

So my questions are:
1- why there are errors in Oracle 11.2.0.1.0 and not in 10.2.0.1.0?
2- If I set ThreadSafe property to True, there is no problem, why should I use this property in Oracle 11g but not in Oracle 10g?
3- If I have Oracle instructions (open on a TOracleDataset by example) in a timer, should I set ThreadSafe property to True?
4- What are the impacts (performance, use) in relation to setting ThreadSafe property to true?

Here is the function I use to execute the TOracleDataSet.open and wait for the end:
unit UExecWithProcMsg;
interface
uses Windows, SysUtils, Classes;
const atl = 'atl.dll';
type
TAtlWaitWithMessageLoop = function(h: THandle): Boolean; stdcall;
TExecFunc = procedure() of object;
TAppliThread = class(TThread)
protected
func: TExecFunc;
procedure Execute; override;
public
constructor Create(func: TExecFunc);
end;

TExecWithProcMsg = class
private
init: Boolean;
HInst: THandle;
FPointer: TFarProc;
altWaitMsgLoop: TAtlWaitWithMessageLoop;
appliTh: TAppliThread;
procedure Initialize();
procedure Finalize();
public
constructor Create();
procedure Exec(func: TExecFunc);
procedure WaitWithMessageLoop(thread: THandle);
end;

implementation

constructor TExecWithProcMsg.Create();
begin
init := false;
inherited Create;
end;

procedure TExecWithProcMsg.Initialize();
begin
HInst := LoadLibrary(atl);
if HInst > 0 then
try
FPointer := GetProcAddress(HInst, PChar('AtlWaitWithMessageLoop'));
if FPointer nil then
begin
altWaitMsgLoop := TAtlWaitWithMessageLoop(FPointer);
end;
except
on E: Exception do
begin
init := false;
raise;
end;
end;
init := true;
end;

procedure TExecWithProcMsg.WaitWithMessageLoop(thread: THandle);
begin
if not init then
begin
try
Initialize;
except
end;
end;
if init then
altWaitMsgLoop(thread)
else // s'il y a un probl
 
I'm not sure if you can display data in a grid from within a thread, unless it is synchronized with the main thread.
 
Synchronization is implicitly maintained because the main thread is waiting. With the windows API function AtlWaitWithMessageLoop, the main thread waits for the object to be signaled, meanwhile dispatching window messages as needed, so windows messages sended by Application.ProcessMessages are processed: the interface is not blocked.

Otherwise, when the main thread is waiting and I start Oracle treatment in a secondary thread (without displaying in a dgbrid) why it works in Oracle 10g, but not in 11g? (External exception in Oracle 11g)

Can you also answer the other questions?
1- why there are errors in Oracle 11.2.0.1.0 and not in 10.2.0.1.0?
2- If I set ThreadSafe property to True, there is no problem, why should I use this property in Oracle 11g but not in Oracle 10g?
3- If I have Oracle instructions (open on a TOracleDataset by example) in a timer, should I set ThreadSafe property to True?
4- What are the impacts (performance, use) in relation to setting ThreadSafe property to true?

Thanks in advance
 
1- why there are errors in Oracle 11.2.0.1.0 and not in 10.2.0.1.0?
2- If I set ThreadSafe property to True, there is no problem, why should I use this property in Oracle 11g but not in Oracle 10g?
I don't know. Bugs in multi-threaded applications are often timing-related, and very difficult to trace.

3- If I have Oracle instructions (open on a TOracleDataset by example) in a timer, should I set ThreadSafe property to True?
You only need to set ThreadSafe to True if multiple threads will be accessing the same session simultaneously.

4- What are the impacts (performance, use) in relation to setting ThreadSafe property to true?
There will be a small performance penalty due to the additional client-side locking/unlocking that the Oracle Client will do.
 
Back
Top