Chee Yap
THINWIRE VISUALIZATION ARCHITECTURE
1. Introduction |
2. General Issues |
3. System Overview |
4. Introduction to Threads |
5. Attribute Objects |
6. Posix Threads |
7. Synchronization |
Appendix A. Non-Blocking Reads |
Appendix B. Thread Program Example |
| (1) |
|
|
ID is a unique identifier generated by the network manager for the request equation (1). Thus, there are actually Lmax-Lmin+1 requests sent on the network with this ID. The data processing thread needs this ID to reassemble the updated data.
pthread_attr_init(pthread_attr_t * attrObj); |
pthread_attr_destroy(pthread_attr_t * attrObj); |
void * myThreadFunc (void *rt) { |
int i; |
for (i - 0; i< 20; i++) |
printf("round pthread_exit(NULL); |
} |
This trivial example executes a for-loop 20 times. Note that the final instruction is a call to pthread_exit().
pthread_t myThr; | // declare thread object "myThr" |
pthread_create(& myThr, NULL, myThreadFunc, NULL); | // create thread with default attribute values |
pthread_join(myThr, NULL); | // parent waits on the child thread to exit |
The ``join value'' (returned by the child thread) is discarded by the parent in this example. Otherwise, instead of NULL, it would be stored at the address indicated by the second argument of pthread_join().
pthread_mutex_t mx; | // declare mutex variable "mx" |
pthread_mutex_init( & mx, NULL); | // NULL is the default mutex attribute object |
... | |
pthread_mutex_lock(& mx); | // lock on mx |
... critical section ... | |
pthread_mutex_unlock(& mx); | // unlock on mx |
... | |
pthread_mutex_destroy(& mx); | // Destroy "mx" |
|
The boundaries between the chunks of data between successive writes are not guaranteed to be preserved as the boundaries between the chunkes of data that is read on the other end. In fact, n ¹ m in general.
You call a function fcntl(int fileDes, int cmd, int arg) where fileDes is the file descriptor (which in this case is a socket but can also be a file or a pipe). The commands cmd of interst here are F_SETFL or F_GETFL. The arg may specify non-blocking or other arguments.
void nonblock (int fd) { |
int flags; |
flags = fcntl(fd, F_GETFL); |
flags |= O_NONBLOCK; |
if (fcntl(fd, F_SETFL, flags) < 0) { error(); } |
} |