[Win32utils-devel] win32/service... still with problems.

Heesob Park phasis at gmail.com
Mon May 22 19:50:53 EDT 2006


2006/5/23, Luis Lavena <luislavena at gmail.com>:
> On 5/22/06, Berger, Daniel <Daniel.Berger at qwest.com> wrote:
> [...]
> > >
> > > Daniel, you tried more than 1 start/stop cycles?
> >
> > Yes.  I ran a series of start/stops as fast as my little fingers would
> > let me.  No problem.
> >
> Me too, I though was my pc, so dumped my p3 800mhz 512mb for a p4,
> 3.0ghz, 1gb... same results.
> > > In the first run, everything worked ok, but several tries
> > > after it, showed that it works "sometimes" and other don't.
> > > (no matter if you left the service running for 1 second or 10 minutes)
> >
> > When you say it didn't work, do you mean that the the service_main or
> > service_stop hooks weren't called?  Or some other error?
> the service_stop hook is called, but the code in there is no executed,
> to the point the service stop responding and service manager report it
> that the pipe has ended or an exception ocurred.
> > > If you see the attached version, service_stop will try to
> > > raise the Interrupt exception so the runner thread gets terminated.
> >
> > Ok, I see the same behavior you mention - the service_stop handler
> > doesn't get executed for some reason.  I think we're back to the thread
> > issues that Heesob mentioned in a previous post about this.
> >
> > Heesob, care to weigh in?
> >
> I didn't get the Heesob reply about this, maybe thats why I keep
> asking the same :-P
I repeat the last answer.

As you know,the win32-service is multithreaded application.
But, Ruby's sleep or select is not compatible with the Thread of Windows.
While executing sleep or select in ruby code,the other thread cannot
do anything.

To workaround this stopping problem,

1. Use loop of short sleep insthead of long sleep.
ex) 10.times { sleep 1 } instead of sleep 10

2. Use nonblocking IO and socket.

> On my freebasic (please, don't think freebasic as old basica, is more
> powerful than that, closer to c, but with basic syntax).
> Anyway, on my framework, I solved this problem executing my Main
> function (which will be service_main in the ruby side) in another
> thread and wait for it to terminate until I destroy the events.
> Also, wouldn't be more correct report to the service manager that
> SERVICE_STOP_PENDING (is stopping) before calling service_stop? in
> service.c:78-83 thre is executed from EventHookHash prior reporting
> the Service Manager that we received the stop signal and we are
> stopping.
> In service.c:114, dwControlCode is evaluated after setting the
> ServiceState, and if it was CONTROL_STOP,  we set the Stop event,
> something that exit service_main prematurely.
> I don't think service.c could be implemented as pure ruby (due
> required native threads)... or not?
I tried but it would't work for now.

The workaround of stopping problem for now is separate service control
process and working process.
In service_main, use system,fork or something create another ruby
program for working process and send kill to it when stop requested.

> Please excuse my english (again), I try to explain better I could, but
> is not easy due: complexity of the topic, and the self-learned nature
> of the language.
> Regards,
> --
> Luis Lavena
> Multimedia systems
> -

Park Heesob

More information about the win32utils-devel mailing list