- use makefile
make
- bulid a server
./server
- build a client
./client [username] 127.0.0.x
(1) Kevin and Amy connect to the server
(2) Kevin says "hello~Amy"
(3) Amy will receive the message
(4) Amy responses "hi~Kevin!"
(5) Kevin will receive the respond
(6) server receives all the messages
- this chatroom accommodates max to 10 clients
- architecture
- workflow
message in shared memory might be changed by new message while not all the clients receive the old message
sem_wait(&mutex); //semaphore wait
while(change); // wait until all the threads receive the message, then we can change the content in shared memory
"critical section"
change=1;
sem_post(&mutex); //semaphore signal
- mutual exclusive : only one thread (client) can change the message content in shared memory at one time
- progress : thread can access to shared momory if all the clients receive the old message (change=0)
- bounded waiting
(1) user interface
(2) have read notice
(3) record chatting history