title: Passing a file descriptor to a thread and using it in the function(homework)
body: <p>My assignment is to do a stripped down multi-threaded mockup of a print server.</p>
  
  <p>The function get_server's prototype is:</p>
  
  <pre><code>void *get_request(void *arg);
  </code></pre>
  
  <p>"The parameter arg points to an open file descriptor from where the request is to be read." So in testing it's recommended to use STDIN_FILENO, but the descriptor needs to be generic when all is said and done.</p>
  
  <pre><code>pthread_create(&amp;tid, &amp;attr, get_request, STDIN_FILENO);
  </code></pre>
  
  <p>Inside the function I'm trying to use arg, and can't change it from a void * to anything usable. For instance none of this works:</p>
  
  <pre><code>read(*arg, intvariable, sizeof(int)); // can't cast void * error
  int fd = *arg; // can't cast void * error
  int fd = *(int *)arg; // seg fault
  int fd = *((int *)arg); // seg fault
  
  int fd = atoi(arg); // seg fault
  // yes I'm aware arg isn't a char* but that's 
  // from the example code we were given
  </code></pre>