| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2902 人关注过本帖
标题:C#做操作系统
只看楼主 加入收藏
zghnxzdcx
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:550
专家分:1176
注 册:2010-4-6
收藏
得分:0 
回复 10楼 jwhandsome521
用微软推出的开发工具和微软竞争?这个想法很有创意啊,哈哈

你永远不可能战胜一个纯傻子,因为他会把你的智商拉到和他同一个水平,然后用他的丰富经验打败你。
2010-07-12 16:23
风飏
Rank: 1
等 级:新手上路
帖 子:16
专家分:4
注 册:2010-7-17
收藏
得分:0 
估计是搞错了  做系统就是做系统 不能说是操作系统啊
2010-07-17 13:33
踏月留香
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-7-17
收藏
得分:0 
代码如下,但目前Resume和Suspend已经过时了,但思想是差不多的。可以修改一下,参考一下。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
//导入Threading,从而可以进行多线程编程
namespace MyTestDemo
{
    //解决操作系统的生产者和消费者问题,其实就是PV问题
    //涉及多线程,已经线程之间的同步
    public class PEDemo
    {
        //定义三个变量,分别代表生产者、消费者和资源的数目
        private int ProductNum = 0;
        private int CustomerNum = 0;
        private int ResourceNum = 0;

        //metrix是用于互斥的信号量,而empty和full用于同步
        public static int metrix = 1;
        public static int empty = 0;
        public static int  full = 0;

        //定义2个栈,用于存放等待线程
        private static  Stack<Thread> waiteStackC = new Stack<Thread>();
        private static  Stack<Thread> waiteStackP = new Stack<Thread>();

        private static  Thread[] productThread;
        private static Thread[] customerThread;

        //定义P操作,P是对信号进行减法,如果小于零,那么该线程挂起
        
        public static void P(ref int tag,int num,string type)
        {
            tag--;
            if (tag < 0)
            {   
                if (type == "p")
                {
                    Console.WriteLine("生产者" + (num + 1).ToString() + "被挂起");
                    productThread[num].Suspend();
                    waiteStackP.Push(productThread[num]);
                }
                else if (type == "c")
                {
                    Console.WriteLine("消费者" + (num + 1).ToString() + "被挂起");
                    customerThread[num].Suspend();
                    waiteStackC.Push(customerThread[num]);
                }
            }
        }

        //定义V操作,V对信号量进行加法,如果加后的值小于等于零,那么唤醒一个线程
        public static void V(ref int tag,string type)
        {
            tag++;
            if (tag <= 0)
            {
                if (type == "p")
                {
                    if (waiteStackC.Count > 0)
                    {
                       
                        Console.WriteLine("一个消费者被唤醒");
                        Thread thr = waiteStackC.Pop();
                        thr.Resume();
                    }
                }
                else if (type == "c")
                {
                    if (waiteStackP.Count > 0)
                    {
                        Console.WriteLine("一个生产者被唤醒");
                        Thread thr = waiteStackP.Pop();
                        thr.Resume();
                    }
                }
            }
        }

        //定义内部类
        public class Product
        {
            int num = 0;
            public Product(int num)
            {
                this.num = num;
            }
            public  void product()
            {
                while (true)
                {
                    P(ref PEDemo.empty, num, "p");
                    P(ref PEDemo.metrix, num, "p");
                    Console.WriteLine("生产者" + (num + 1).ToString() + "生产一个产品");
                    V(ref PEDemo.metrix, "p");
                    V(ref PEDemo.full, "p");
                }
            }
        }

        public class Customer
        {
            int num = 0;
            public Customer(int num)
            {
                this.num = num;
            }
            public void customer()
            {
                while (true)
                {
                    P(ref PEDemo.full, num, "c");
                    P(ref PEDemo.metrix, num, "c");
                    Console.WriteLine("消费者" + (num + 1).ToString() + "消费一个产品");
                    V(ref PEDemo.metrix, "c");
                    V(ref PEDemo.empty, "c");
                }
            }
        }

        //用于初始化
        public PEDemo()
        {
            try
            {
                Console.WriteLine("生产者数目为?");
                ProductNum=Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("消费者数目为?");
                CustomerNum=Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("资源数目为?");
                ResourceNum=Convert.ToInt32(Console.ReadLine());
                //初始化full信号量
                full = ResourceNum;

                productThread=new Thread[ProductNum];
                customerThread=new Thread[CustomerNum];

                for (int i = 0; i < ProductNum; i++)
                {
                    Product p = new Product(i);
                    productThread[i] = new Thread(new ThreadStart(p.product));
                    productThread[i].Start();
                }

                for (int i = 0; i < CustomerNum; i++)
                {
                    Customer c = new Customer(i);
                    customerThread[i] = new Thread(new ThreadStart(c.customer));
                    customerThread[i].Start();
                }
            }
            catch(FormatException ex)
            {
                Console.WriteLine("您输入的格式有误");
            }
        }

      

        public static void Main(string[] args)
        {
            PEDemo pe = new PEDemo();
        }
    }
}
2010-07-17 19:48
踏月留香
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2010-7-17
收藏
得分:0 
修改后的:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
//导入Threading,从而可以进行多线程编程
namespace MyTestDemo
{
    //解决操作系统的生产者和消费者问题,其实就是PV问题
    //涉及多线程,已经线程之间的同步
    public class PEDemo
    {
        //定义三个变量,分别代表生产者、消费者和资源的数目
        private int ProductNum = 0;
        private int CustomerNum = 0;
        private int ResourceNum = 0;

        //metrix是用于互斥的信号量,而empty和full用于同步
        public static int metrix = 1;
        public static int empty = 0;
        public static int  full = 0;

        //定义4个栈,用于存放等待线程
        private static  Stack<Thread> waiteStackC = new Stack<Thread>();
        private static  Stack<Thread> waiteStackP = new Stack<Thread>();
        private static Stack<Thread> waiteStackCM = new Stack<Thread>();
        private static Stack<Thread> waiteStackPM = new Stack<Thread>();

        private static  Thread[] productThread;
        private static Thread[] customerThread;

        //定义P操作,P是对信号进行减法,如果小于零,那么该线程挂起
        
        public static void P(ref int tag,int num,string type,string tag1)
        {
            tag--;
            if (tag < 0)
            {   
                if (type == "p")
                {
                    Console.WriteLine("生产者" + (num + 1).ToString() + "被挂起");
                    if (tag1 == "m")
                        waiteStackPM.Push(Thread.CurrentThread);
                    else if(tag1=="n")
                        waiteStackP.Push(Thread.CurrentThread);
                    Thread.CurrentThread.Suspend();
                  
                }
                else if (type == "c")
                {
                    Console.WriteLine("消费者" + (num + 1).ToString() + "被挂起");
                    if (tag1 == "m")
                        waiteStackCM.Push(Thread.CurrentThread);
                    else if(tag1=="n")
                        waiteStackC.Push(Thread.CurrentThread);
                    Thread.CurrentThread.Suspend();
                }
            }
        }

        //定义V操作,V对信号量进行加法,如果加后的值小于等于零,那么唤醒一个线程
        public static void V(ref int tag,string type,string tag1)
        {
            tag++;
            if (tag <= 0)
            {
                if (type == "p")
                {
                        if (tag1 == "m")
                        {
                            if (waiteStackCM.Count > 0)
                            {
                                Thread thr = waiteStackCM.Pop();
                                thr.Resume();
                            }
                        }
                        else if (tag1 == "n")
                        {
                            if (waiteStackC.Count > 0)
                            {
                                Thread thr = waiteStackC.Pop();
                                thr.Resume();
                            }
                        }
                        Console.WriteLine("一个消费者被唤醒");
                }
                else if (type == "c")
                {
                        if (tag1 == "m")
                        {
                            if (waiteStackPM.Count > 0)
                            {
                                Thread thr = waiteStackPM.Pop();
                                thr.Resume();
                            }
                        }
                        else if (tag1 == "n")
                        {
                            if (waiteStackP.Count > 0)
                            {
                                Thread thr = waiteStackP.Pop();
                                thr.Resume();
                            }
                        }
                        Console.WriteLine("一个生产者被唤醒");
                }
            }
        }

        //定义内部类
        public class Product
        {
            int num = 0;
            public Product(int num)
            {
                this.num = num;
            }
            public  void product()
            {
                while (true)
                {
                    P(ref PEDemo.empty, num, "p","n");
                    P(ref PEDemo.metrix, num, "p","m");
                    Console.WriteLine("生产者" + (num + 1).ToString() + "生产一个产品");
                    V(ref PEDemo.metrix, "p","m");
                    V(ref PEDemo.full, "p","n");
                }
            }
        }

        public class Customer
        {
            int num = 0;
            public Customer(int num)
            {
                this.num = num;
            }
            public void customer()
            {
                while (true)
                {
                    P(ref PEDemo.full, num, "c","n");
                    P(ref PEDemo.metrix, num, "c","m");
                    Console.WriteLine("消费者" + (num + 1).ToString() + "消费一个产品");
                    V(ref PEDemo.metrix, "c","m");
                    V(ref PEDemo.empty, "c","n");
                }
            }
        }

        //用于初始化
        public PEDemo()
        {
            try
            {
                Console.WriteLine("生产者数目为?");
                ProductNum=Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("消费者数目为?");
                CustomerNum=Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("资源数目为?");
                ResourceNum=Convert.ToInt32(Console.ReadLine());
                //初始化full信号量
                full = ResourceNum;

                productThread=new Thread[ProductNum];
                customerThread=new Thread[CustomerNum];

                for (int i = 0; i < ProductNum; i++)
                {
                    Product p = new Product(i);
                    productThread[i] = new Thread(new ThreadStart(p.product));
                    productThread[i].Start();
                }

                for (int i = 0; i < CustomerNum; i++)
                {
                    Customer c = new Customer(i);
                    customerThread[i] = new Thread(new ThreadStart(c.customer));
                    customerThread[i].Start();
                }
            }
            catch(FormatException ex)
            {
                Console.WriteLine("您输入的格式有误");
            }
        }

      

        public static void Main(string[] args)
        {
            PEDemo pe = new PEDemo();
        }
    }
}
2010-07-18 09:21
小菰
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-7-27
收藏
得分:0 
有创意!拿微软的东西和微软竞争。。。
2010-07-27 23:45
c1_wangyf
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:7
帖 子:665
专家分:2832
注 册:2010-5-24
收藏
得分:0 
以下是引用liu30211在2010-6-29 23:00:37的发言:

想法完全不对

C#    本来就是依靠WINDOWs平台 才能使用
要做系统用C语言
haha,正如这位朋友所说!!
2010-08-04 15:17
dllnetspy
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2010-8-3
收藏
得分:0 
楼猪有才了
2010-08-30 17:29
niulang
Rank: 1
来 自:河北-石家庄
等 级:新手上路
帖 子:75
专家分:0
注 册:2009-4-16
收藏
得分:0 
哪位高手直接上传一个做好的操作系统源程序啊,我这学期的课程设计正发愁呢

牛郎不爱织女
2010-11-09 08:27
快速回复:C#做操作系统
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022500 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved