请参考使用TCriticalSection对象。

解决方案 »

  1.   

    TCriticalSection,是什么,能说的具体点吗,
    还有,我在线程中的两个过程是顺序执行,没有同步啊?
      

  2.   

    procedure autothread.Execute;begin
      { Place thread code here }
      while not terminated do
          begin          autottoscop;////是个声明的第一个过程
              autosctotop;//是个声明的第二个过程
          end;end;
    两个过程的程序大体相同,就是对不同的表进行操作。
    第一个过程的程序:
    procedure autothread.autottoscop;
    begin
        //sleep(3000);
        //写代码
         if autot.Active then autot.close;
         autot.Open;
         if autot.RecordCount =0 then
            begin
               autot.close;
               enabledop;
               exit;
            end;
         if autot.RecordCount <>0 then
            begin
              对表进行写操作
             end;
    第二个过程:
    第一个过程的程序:
    procedure autothread.autosctotop;
    begin
        //sleep(3000);
        //写代码
         if autosc.Active then autosc.close;
         autosc.Open;
         if autosc.RecordCount =0 then
            begin
               autot.close;
               enabledop;
               exit;
            end;
         if autosc.RecordCount <>0 then
            begin
              对表进行写操作
             end;当表autot,autosc中的记录都为0时,程序没有问题。
    当第一过程中的表autot有记录时,执行完autottoscop,到第二个过程的时候就出错了。
      

  3.   

    在用断点跟踪中,发现在线程的运行中,有时候 线程的terminated 值变成无值,(正常应是false,让线程不停的运行)。有什么操作能使terminated的值发生变化呢,我在程序中从来都没有改变它。
      

  4.   

    用断点跟踪中,程序每一步都没有出错,编译成.exe .
    但在.exe中执行时,线程进行一次循环后,整个应用程序就退出了,是Delphi4的毛病吗