semaphore and mutex/pthreads

Diff between semaphore and mutex.
Defn-1. Then a mutex is usually used for mutual exclusion of critical paths, while a semaphore is used for inter-thread synchronization and   event notifications.
Defn-2. A "mutex" (or "mutual exclusion lock") is a signal that two or more
asynchronous processes can use to reserve a shared resource for exclusive use.
 
The first process that obtains ownership of the "mutex" also obtains ownership of the shared resource. Other processes must wait for for the first process to release it's ownership of the "mutex" before they may attempt to obtain it.
 
Finally, a "semaphore" is a sort of "mutex" that is used to signal the availability of a plentiful resource. The source of the resource adds one to the semaphore for each unused resource available. As resources are taken away, the count in the semaphore is decremented (one for each removed resource) until it reaches zero (meaning that no more resources are available). At this
point, any remaining consumers of the resource must wait until the "semaphore" increments above zero, indicating that more resources are available.

Reference:
PThreads Primer
PThreads Manual

Diff between TCP and UDP

diff1=As a connectionless protocol, UDP does not incorporate any connection establishment, teardown, or maintenance logic. For example, a server supporting a UDP application with multiple simultaneous clients will need to allocate less memory to support these clients than would the corresponding TCP application server. Bandwidth throttling and in-order delivery features are properties of TCP, not UDP.

diff2= User Datagram Protocol (UDP)
The User Datagram Protocol (UDP) is a connectionless transport-layer protocol (Layer 4) that belongs to the Internet protocol family. UDP is basically an interface between IP and upper-layer processes. UDP protocol ports distinguish multiple applications running on a single device from one another.

Unlike the TCP, UDP adds no reliability, flow-control, or error-recovery functions to IP. Because of UDP's simplicity, UDP headers contain fewer bytes and consume less network overhead than TCP.

UDP is useful in situations where the reliability mechanisms of TCP are not necessary, such as in cases where a higher-layer protocol might provide error and flow control.
UDP is the transport protocol for several well-known application-layer protocols, including Network File System (NFS), Simple Network Management Protocol (SNMP), Domain Name System (DNS), and Trivial File Transfer Protocol (TFTP).

No comments: