Forum 1 Grupy Ćwiczeniowej
Forum studentów informatyki Politechniki Białostockiej
FAQ
Szukaj
Użytkownicy
Grupy
Galerie
Rejestracja
Profil
Zaloguj
Forum Forum 1 Grupy Ćwiczeniowej Strona Główna
->
Systemy operacyjne
Napisz odpowiedź
Użytkownik
Temat
Treść wiadomości
Emotikony
Więcej Ikon
Kolor:
Domyślny
Ciemnoczerwony
Czerwony
Pomarańćzowy
Brązowy
Żółty
Zielony
Oliwkowy
Błękitny
Niebieski
Ciemnoniebieski
Purpurowy
Fioletowy
Biały
Czarny
Rozmiar:
Minimalny
Mały
Normalny
Duży
Ogromny
Zamknij Tagi
Opcje
HTML:
TAK
BBCode
:
TAK
Uśmieszki:
TAK
Wyłącz HTML w tym poście
Wyłącz BBCode w tym poście
Wyłącz Uśmieszki w tym poście
Kod potwierdzający: *
Wszystkie czasy w strefie EET (Europa)
Skocz do:
Wybierz forum
To już 5 semestr???
----------------
Programowanie systemów aplikacyjnych
Metody probabilistyczne i statystyka
Grafika komputerowa
Systemy operacyjne
Układy elektroniczne
Systemy ekspertowe
Angielski
Architektura Komputerów
Bazy Danych
Systemy Samouczące
Bezpieczeństwo Systemów Komputerowych
Systemy Operacyjne 2
Programowanie Obiektowe
Statystyka 2
OiPL [o ile cos takiego bedzie]
Linux
4 semestr
3 semestr
Chillout
----------------
Spam Room
Humor
ShoutBox
Przegląd tematu
Autor
Wiadomość
wicher
Wysłany: Pon 18:36, 09 Cze 2008
Temat postu:
Dziękuję. A co do max punktów to akurat tyle nie potrzebuję. Wystarczy 15-20 pkt; tak w sam raz żeby zaliczyć i mieć z głowy(przynajmniej do nastepnego semestru).
boro
Wysłany: Pon 18:33, 09 Cze 2008
Temat postu:
teraz zostaje zrozumiec o co kaman w tym kodzie, ladna dokumentacja i max punktow wicher inkasujesz ;) co do reniferow to na trojeczke mam juz zrobione, wiecej mi chyba nie jest potrzebne. owocnej pracy zycze.
wicher
Wysłany: Pon 18:30, 09 Cze 2008
Temat postu:
Dzięki Boro. Wyszukiwać z google potrafię. Problem stanowiło te ponad 4 tysiące stron. Trochę to trwało, ale już znalazłem nawet w C gotowy program. No i oczywiście ten kod w javie, który ty zamieściłeś ale czy źle patrzyłem i nie zauważyłem, czy też nie ma tam tych brakujących klas.
PS znalazłem też cos o mikołajach i reniferach
boro
Wysłany: Pon 17:32, 09 Cze 2008
Temat postu:
www.google.pl
-> sleeping barber problem
przeszukaj wyswietlone strony. moze znajdziesz to czego szukasz. zycze powodzenia ;)
wicher
Wysłany: Pon 15:13, 09 Cze 2008
Temat postu:
boro napisał:
trzeba dobrze poszukac, no i znajomosc angielskiego czasami tez pomaga
Akurat ten kod programu umknął moim poszukiwaniom. Większość kodu który znalazłem była niekompletna - zawierała tylko wątki fryzjera i klienta plus semafory, a to znaleźć mogłem na prawie każdej stronie po wpisaniu w googlach "problem śpiącego fryzjera"
A tak wogóle to kod, który umieściłeś, wykazuje pewne braki. Brakuje m.in. klas:
- ConsumerWithSemaphores;
- ProducerWithSemaphores;
- CircularBufferWithSemaphores.
Najpewniejszym rozwiązaniem byłby kod w C chyba, że brakujące klasy do powyższego kodu są gdzieś dostępne na stronie skąd zaczerpnąłeś program. Dzięki za pomoc
boro
Wysłany: Pon 13:59, 09 Cze 2008
Temat postu:
trzeba dobrze poszukac, no i znajomosc angielskiego czasami tez pomaga. znalezione na jakiejs stronce. moze zadziala:
Kod:
/*
A Solution to Sleeping Barber problem using semaphores:
Solution uses a circular buffer with synchronized put and take methods.
Abstract classes ConsumerWithSemaphores and ProducerWithSemaphores
are inherited.
*/
import javax.swing.*;
import java.awt.*;
/*
Application creates a window -
packages javax.swing and java.awt are used
*/
import java.awt.event.*;
import java.util.*;
// Class to represent customers
class Customer
{
private int custNo;
public Customer(int no)
{
custNo = no;
}
public String toString()
{
return "Customer number " + custNo;
}
}
/*
* Class for barber = consumer of customers
*/
class Barber extends ConsumerWithSemaphores implements Runnable
{
private String name = "Semaphoric barber";
private int maxCutTime;
private JTextArea noteBoard;
private Random rndGen;
public Barber(CircularBufferWithSemaphores cb,int maxTime, JTextArea jta)
{
super(cb);
maxCutTime = maxTime;
noteBoard = jta;
rndGen = new Random();
}
protected void consume(Object obj)
{
// We get Objects from buffer -> must cast
Customer c = (Customer)obj;
noteBoard.append(name + " starts cutting the hair of " + c +"\n");
try
{
Thread.sleep(1000 + Math.abs(rndGen.nextInt(1000 * maxCutTime)) );
}
catch(InterruptedException ie)
{
Thread.currentThread().interrupt();
}
noteBoard.append(name + " stopped cutting the hair of " + c+"\n");
}
public void run()
{
Object obj;
while(!Thread.interrupted())
{
try
{
if( getNumStored() == 0 )
noteBoard.append(name + " sleeping.\n");
obj = takeObject();
consume(obj);
}
catch(InterruptedException ie)
{
break;
}
}
}
}
/*
* Class to produce customers for barber.
* Customer created at random intervals.
*/
class CustomerAppearance extends ProducerWithSemaphores implements Runnable
{
private int maxAppearTime;
private JTextArea noteBoard;
private int CustomerNum = 0;
private Random rndGen;
public CustomerAppearance(CircularBufferWithSemaphores cb,
int maxTime,JTextArea jta)
{
super(cb);
maxAppearTime = maxTime;
noteBoard = jta;
rndGen = new Random();
}
protected Object produce()
{
Object obj;
try
{
Thread.sleep(1000 + Math.abs(rndGen.nextInt(1000 * maxAppearTime)) );
}
catch(InterruptedException ie)
{
;
}
CustomerNum++;
obj = new Customer(CustomerNum);
return obj;
}
public void run()
{
Customer c;
while(true)
{
try
{
// Produce outputs objects -> must cast
c = (Customer)produce();
putObject(c);
noteBoard.append(""+ c + "arrived.+\n");
}
catch(InterruptedException ie)
{
break;
}
}
}
}
/*
* The main program with simple UI
* Customer producing thread is started with program
* Barber thread started and stopped from push button
* once stopped can not be restarted.
*/
public class BarberShop extends JFrame implements WindowListener,ActionListener
{
CustomerAppearance caQueue = null;
Barber theBarber;
Thread BarberThread;
Thread CustomerThread;
JButton startButton;
JTextArea threadNote = null;
CircularBufferWithSemaphores chairs = null;
public BarberShop()
{
// Set layout manager
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
// Set window title
this.setTitle("Sleeping Barber program.");
//Set window size
this.setSize(470,400);
this.setResizable(false);
startButton = new JButton("Start/stop Barber");
getContentPane().add(startButton);
startButton.addActionListener(this);
threadNote = new JTextArea(18,40);
JScrollPane jScrollView = new JScrollPane(threadNote);
getContentPane().add(jScrollView);
try
{
chairs = new CircularBufferWithSemaphores(4);
}
catch(IllegalArgumentException iae)
{
System.exit(-1);
}
// Create threads for producer and consumer but
// do not yet start:
caQueue = new CustomerAppearance(chairs,3,threadNote);
theBarber = new Barber(chairs,5,threadNote);
BarberThread = new Thread(theBarber);
CustomerThread = new Thread(caQueue);
}
public static void main(String [] argv )
{
BarberShop bsProg = new BarberShop();
// Show window
bsProg.show();
// Add the window self as a listener!
bsProg.addWindowListener(bsProg);
// Start the customer producing thread
bsProg.CustomerThread.start();
}
/* These methods must be implemented because of interfac,
but they can be left empty */
public void windowOpened(WindowEvent e){ }
public void windowClosed(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
// Only this method needs code!
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
// Only method of ActionListener
public void actionPerformed(ActionEvent ae)
{
if( ae.getSource() == startButton)
{
// If barber thread is running stop it - else start
if(BarberThread.isAlive())
{
BarberThread.interrupt();
}
else
{
BarberThread.start();
}
}
}
}
wicher
Wysłany: Pon 12:28, 09 Cze 2008
Temat postu:
Może ktokolwiek posiada rozwiązanie problemu śpiącego fryzjera na semaforach. Może być w Javie, w C, w C++ czy cokolwiek, byle było działające. Aha - opcjonalnie może być wielu fryzjerów.
vbazyl
Wysłany: Pon 2:52, 21 Kwi 2008
Temat postu:
A jeśli nie spełnię 3 warunku to źle??
boro
Wysłany: Pon 1:13, 21 Kwi 2008
Temat postu: PS9 - programy
Potok nazwany. Powiedzmy ze jest to niemal rozwiazanie zadania nr 1 z kartki ktora kobieta dala nam na ostatnich zajeciach. Fifo dziala w jedna strone jak narazie.
Instrukcja obslugi:
1. po wpisaniu nazwy pliku nalezy wcisnac ENTER
2. nalezy wklepac jakis znak i wcisnac ENTER
3. nalezy cieszyc sie z oczekiwanego wyniku ;)
Kod:
#include<stdlib>
#include<stdio>
#include<unistd>
#include<sys>
#include<sys>
#include<fcntl>
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define MAX 100
int main(void)
{
int writefd;
int readfd;
mkfifo("FIFO1",FILE_MODE);
mkfifo("FIFO2",FILE_MODE);
char buf1[MAX];
char buf2[max];
int pid=fork();
switch(pid)
{
case -1:{
printf("blad");
break;
}
default:{ //macierzysty
writefd=open("FIFO1",O_WRONLY); //zapis do kolejki fifo 1
readfd=open("FIFO2",O_RDONLY); //bedzie czytac z fifo 2
printf("podaj nazwe pliku\n");
scanf("%s\n",buf2);
write(writefd,buf2,MAX);
wait(NULL);
break;
}
case 0:{ //potomny
readfd=open("FIFO1",O_RDONLY); //potomny czyta z fifo 1
writefd=open("FIFO2",O_WRONLY); //potomny zapisuje do fifo 2
read(readfd,buf1,MAX);
printf("\nodczytano z kolejki: %s",buf1);
break;
}
}
unlink("FIFO1");
unlink("FIFO2");
return 0;
}
fora.pl
- załóż własne forum dyskusyjne za darmo
Powered by
phpBB
© 2001, 2005 phpBB Group
deoxBlue v1.0 // Theme created by
Sopel stylerbb.net & programosy.pl
Regulamin