Пример #1
0
 public PCB(string name)
 {
     Name                       = name;
     stopped                    = true;
     blocked                    = false;
     in_smc                     = 0;
     stop_waiting               = false;
     message_semaphore_common   = new Semaphore(0);
     message_semaphore_receiver = new Semaphore(0);
     first_message              = null;
     next_semaphore_waiter      = null;
     stopper_semaphore          = new Semaphore(0);
     Stoppe_semaphore           = new Semaphore(0);
     next_pcb_this_group        = null;
     last_pcb_this_group        = null;
     next_pcb_all               = null;
     last_pcb_all               = null;
     Parent                     = null;
     First_son                  = null;
     auto_storage_addres        = -1;
     auto_storage_size          = 0;
     Auto_data_addres           = -1;
     Auto_data_size             = 0;
     Auto_stack_addres          = -1;
     Auto_stack_size            = 0;
 }
Пример #2
0
        public void XS(string receiver_name, string sender_name, string text) // uważam za zbędny parametr, jakim jest długość komunikatu, przynajmniej przy braku alokacji pamięci przez Pawła, dodałem nazwę odbiorcy
        {
            PCB sender = XN(sender_name);

            if (sender != null)
            {
                PCB receiver = XN(receiver_name);
                if (receiver != null)
                {
                    Komunikat komunikat = new Komunikat(ref sender, text);
                    receiver.Message_semaphore_common.P();
                    //receiver.Message_semaphore_receiver.P(ref komunikat);
                    receiver.Message_semaphore_receiver.V(ref receiver);
                    if (receiver.First_message == null || receiver.Message_semaphore_receiver.Value == 1)
                    {
                        receiver.First_message = komunikat;
                    }
                    else if (receiver.Message_semaphore_receiver.Value > 1)
                    {
                        Komunikat temp = receiver.First_message;
                        while (temp != null)
                        {
                            if (temp.Next == null)
                            {
                                temp.Next = komunikat;
                                break;
                            }
                            temp = temp.Next;
                        }
                    }

                    receiver.Message_semaphore_common.V();
                    Console.WriteLine("Wysłano komunikat.");
                }
                else
                {
                    XQUE();
                    Console.WriteLine("Błędny odbioraca. \nW programie XS");
                }
            }
            else
            {
                XQUE();
                Console.WriteLine("Błędny nadawca. \nW programie XS");
            }
        }