This assignment is simple. Your server will calculate 'pi'.
When someone connects to it's TCP socket, it will send the current best
estimate of 'pi' to that socket. You don't have to write your own client. Just use telnet.
Computing PI:
Throw a bunch of darts at a dartboard
of size 1x1. Count those that land in the circle who's radius is
0.5, and those that land in the corners of the square. The ratio
and some math will tell you 'pi'. Use double precision
math. Please note there are better ways; this is just the easiest
way.
How To Do The Networking
You can use sigio. You can use threads. You will get more points if you do both.
Locking
It does not matter if you use sigio or threads, you will still need to do locking.
Avoiding Blocking with sigio:
Just because SIGIO says there is action
does not mean there is actually action. The action might have
disappeared. I suggest O_NONBLOCK used pretty much everywhere,
and lots of if statements.
Avoiding blocking with threads:
One thread does the networking. One thread does the computation. The computation thread never does networking. THE NETWORKING THREAD NEVER HOLDS THE LOCK WHILE DOING NETWORKING.
Points
3 Uses SIGIO correctly
3 Does threads correctly
3 Does threads in Java and C++ correctly
1 Computes and networks using fork and shared memory.
1 Locks correctly (or does not need to)
1 Computes PI
1 Does not pause even on write()
1 Telnetting to the thing produces an estimate for pi
1 Uses threads to compute on 2 CPUs
-1 Turned in each day after Mon Sep 23.