Dominique Pelle wrote:

> ...snip...
> >> Without marking the variable volatile, there is a risk I think,
> >> that some compilers might optimize making code incorrect
> >> sometimes by not seeing that the variable gets automagically
> >> updated asynchronously by a signal handler as explained here
> >> for example:
> >>
> >> http://www.linuxdevices.com/articles/AT5980346182.html
> >>
> >> These kind of bugs can be subtle and hard to reproduce.
> >>
> >> I also see other variables in Vim which are modified or read
> >> by signal handlers. They should in theory also be declared
> >> volatile:
> >>
> >> - do_resize (modified by signal handler sig_winch())
> >> - got_int =A0(modified by signal handler catch_sigint())
> >> - sig_alarm_called (modified by signal handler sig_alarm())
> >> - full_screen (modified by signal handler deathtrap())
> >> - in_mch_delay (read by signal handler deathtrap())
> >> - lc_active (read by signal handler deathtrap())
> >> - sigcont_received (modified by signal handler sigcont_handler())
> >> (maybe others)
> >
> > I hate this kind of "blame the programmer" solutions. =A0It means compile=
> r
> > writers are lazy and put the burden of getting it right on the
> > programmer. =A0While the actual problem is that the compiler should do
> > this correctly automatically. =A0The compiler can see that the variable i=
> s
> > used in a signal handler and act accordingly.
> 
> Asynchronous things are hard to get right.
> 
> In the case of static variables, the compiler could indeed in theory
> figure it out (no idea whether it actually does that). But at least in
> the case of global variables such as 'got_int' compiler has no way
> to know that 'got_int' is used in a signal handler in another object
> file.

That's the problem with C, you can do things in another file that are
only detected when linking object files together.  It's even worse for
C++ (does someone collect cryptic C++ link errors?).

> > Anyway, compilers do work in this broken way, I suppose we should add
> > these volatile keywords to avoid trouble.
> 
> It's safer. Attached patch contains all changes made in previous
> patch and declares a few more 'volatile' variables used in signal
> handlers.

Thanks, I'll include it one of these days.

-- 
hundred-and-one symptoms of being an internet addict:
129. You cancel your newspaper subscription.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui