人如计算机里的一个线程

Filed Under (默认分类) by 刘 鹏 on 21-05-2007

  《疯狂的石头》里的谢小盟说:“城市是母体”,刘某说:“城市是计算机,而我们就生活在他的CPU里,机器啊,伟大的机器”。

   最近越来越觉得自己像是操作系统进程中可以并行执行的程序段—多线程,以下用C#语言描述了我的生活。

 

class 人

 {

  public void 吃饭()

  {

    //吃饭…

  }

  public void 工作()

  {

          //工作…

  }

  public void 睡觉()

  {

          //睡觉…

  }

  public void 死了()

  {

   this.活着的 = false;

  }

  public bool 活着的;

 }

 class world

 {

  public static System.Threading.Thread 我的生活;

 

  static void Main(string[] args)

  {

   我的生活 = new System.Threading.Thread(new System.Threading.ThreadStart(world.mylift));

   我的生活.Start();

  }

  private static void mylift()

  {

   人 我 = new 人();

   我.活着的 = true;

   while(我.活着的)

   {

    try

    {

     我.吃饭();

     我.工作();

     我.睡觉();

    }

    catch

    {

     我.死了();

    }

             System.Threading.Thread.Sleep(86400000);

   }

  }

 }

Comments:

Post a comment

You must be logged in to post a comment.