RE:Re: Is ROOT thread-safe?

Masaharu Goto (MXJ02154@nifty.ne.jp)
Sun, 15 Nov 1998 23:45:00 +0900


Victor,

>Due to CINT is not thread safe only the main thread can use CINT,
>the other threads should be precompiled.

This is correct. If you have precompiled thread-safe function, you could
use multi-thread provided that you have only one CINT thread.

>> The Win32 version of ROOT runs always in multi-threaded mode. There
>> are three threads: user input, command processor (CINT), graphics.
>> That part has been developed by Valery Fine.
>
>But there is no yet option for user defined threads.

User defined thread capability for Win32 will be supported in comming CINT
version 5.13.80. It will support following Win32 API in lib/win32api
optional library. You'll need to run lib/win32api/setup.bat script.

CreateThread
WaitForSingleObject
InitializeCriticalSection
EnterCriticalSection
LeaveCriticalSection
DeleteCriticalSection

Example source is shown below.

--------------------------------------------------------------------
// thread.h , Source for precompiled function. Do following to
// precompile this source.
// c:\> makecint -mk makethread -dl thread.dll -H thread.h
// c:\> make -f makethread
//
#include <iostream.h>
#include <windows.h>

class FuncData {
public:
FuncData(int nin,char *msgin,LPCRITICAL_SECTION lpcin)
{ n=nin; msg=msgin; lpc=lpcin; }
int n;
char *msg;
LPCRITICAL_SECTION lpc;
};

int PrecompiledFunc(void *p) {
FuncData *px=(FuncData*)p;
cout << "ThreadID=" << GetCurrentThreadId() << endl;
for(int i=0;i<px->n;i++) {
EnterCriticalSection(px->lpc);
cout << px->msg << " i=" << i << endl;
LeaveCriticalSection(px->lpc);
}
return(i);
}

--------------------------------------------------------------------------
// main.cxx , interpreted source
// c:\> cint main.cxx
//
#include <windows.h>
#include <iostream.h>
#include "thread.dll"

int InterpretedFunc(void *p) {
struct FuncData *px=(struct FuncData*)p;
cout << "ThreadID=" << GetCurrentThreadId() << endl;
for(int i=0;i<px->n;i++) {
EnterCriticalSection(px->lpc);
cout << px->msg << " i=" << i << endl;
LeaveCriticalSection(px->lpc);
}
return(i);
}

int main() {
CRITICAL_SECTION c;
InitializeCriticalSection(&c);

FuncData background(10,"Compiled backgrond",&c);
FuncData interpreted(5,"Interpreted foreground",&c);
FuncData foreground(5,"Compiled foreground",&c);

DWORD ThreadID;
HANDLE h= CreateThread(NULL,0
,(LPTHREAD_START_ROUTINE)PrecompiledFunc
,&background,0
,&ThreadID);

InterpretedFunc(&interpreted);
PrecompiledFunc(&foreground);

WaitForSingleObject(h,1000); // Wait for background job to finish
DeleteCriticalSection(&c);
}
------------------------------------------------------------------------

>I want to add that on some platforms ( like linux, SGI ) there is
>a threadsafe X11.

At this moment, multithread for UNIX platform is not implemented.

Masaharu Goto