I found this program in a forum and here thread1 may read one more string and thread2 displays the last read string(because of delay due tosleep(5) in write1() operation).So,serial read and write is not achieved and we can expect the same even if we dont add sem_wait(&len); sem_post(&len); in this program.Then what kind of synchronisation is achieved in this program by this semaphore addition?
what kind of synchronisation is achieved in this program by this semaphore addition?
I think you're missing the point.
The program runs in an infinite loop:
read1() reads a string into global buffer.
write1() waits for the string to be entered and prints it when it's available.
The semaphore is used to implement that syncronisation.