On Mon, 24 May 2010, Vailton Renato wrote:

Hi,

> > I was making some tests with testsvc.prg (Harbour SVN 5.5.1 + BCC) and
> > discovered some problems because it does not execute correctly when
> > compiled with "-mt" in hbmk2. Apparently the problem comes in
> > win_serviceStart () but I could not detect why the service does not
> > run.
> Using log files, I discovered that the problem occurs in function
> hb_vmRequestReenter () and not in function win_serviceStart () as I
> suspected initially. I'm still doing some tests to see what might be
> influencing this behavior, but so far not encountered any problem.

I'm not familiar with services in MS-Windows so I hope that real
MS-Windows programmers can verify the text below.
MSDN says that StartServiceCtrlDispatcher() makes calling thread
service dispatcher which creates new thread to execute the appropriate
ServiceMain function when a new service is started.
It means that current win_svc.c code cannot work with MT HVM because
it does not initialize new HVM stack for newly created thread.
It also does not unlock HVM stack used by thread calling
StartServiceCtrlDispatcher() what will cause deadlock when some other
thread activates GC.
It works with ST HVM because thread created for ServiceMain function
reuses the HVM stack bound with thread calling StartServiceCtrlDispatcher()
taking its address from static variable.
It does not work with MT HVM because in MT mode each HVM thread extracts
HVM stack pointer from TLS so newly create thread takes NULL as its own
stack pointer.

If you want to use this code with MT HVM then it has to be adopted to
work safely with it. It should create and destroy on exit new HVM stack
and encapsulate call to StartServiceCtrlDispatcher() into hb_vmUnlock()/
hb_vmLock().

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to