Linux Threading
Date: 10/06/05

Date: 6 Oct 2005 09:42:14 -0700

Let me start off by saying that I have googled and wikki and most of
the material that comes up with Linux threads is confusing and or
dated. After tracing through a rather remarkable growth of threading
lineage from an original Linux vs Posix threads, NTPL and others, that
today pthreads API now is the most official Linux threading API. My
questions have more to do with best practices for i/o under Linux in a
threaded context, and also, perhaps exploring some evil thing.

I apologize for the length of this post in advance. If there is a
definitive and up to date FAQ for these sorts of questions, please
point me to it. If not, then, I'll assemble your answers into a
definitive thread FAQ under Linux and I'll host it on my Linux blog.

1) What's considered safe practice under Linux I/O for threading?

I'm a Windows guy and I'm used to accepting a socket connection on one
thread, then, passing it off to another thread to connect and then
process. Same for file handles. Under Linux, I understand that file
handles and socket handles are really the same thing, but, when can I
move them around?

Can I move them around across thread boundaries?

Can I share them (guarding of course with a mutex of course), across
multiple threads?

For the case of disk I/O, and assuming I have my own mechanism to
preserve coherency, should I have one file handle shared, or should I
have multiple thread specific file handles sharing the file? Are the
file apis thread safe? My concern with multiple file handles is what
happens with file buffering. Like, I could write to FILE one thread
but that would be buffered, but the file handle for the same file on
another thread would have its own set of buffers.

Relevant Pages

  • Re: feasibilty of the memset operation on the FILE streams
    ... stdin in linux is linebuffered or unbuffered. ... Exactly which way the buffering is handled depends on the operational ... newsgroup for the exact details. ... Lew Pitcher, IT Consultant, Enterprise Data Systems ...
  • Re: Linux, X, ld, gcc, linking, shared libraries and stuff
    ... An objective opinion. ... Linux may well grow into a very usable option with time. ... And btw, I am tired of hearing flopp words like "double buffering" or "displaylists", repeated over and over, without any useful details. ... But this is an opinion, a guess, so thats it. ...
  • Re: Pipes, cat buffer size
    ... decouples how the reader and the writer interact. ... the reader will be forced to read each byte individually. ... it switches between async in-kernel buffering (<8192 ... Linux isn't actually much better, ...
  • =?utf-8?Q?Re:=20-buffering=20with=20CDC=20serial=20port=20on=20wi?= =?utf-8?Q?ndows?=
    ... |> Skimming through the TCL-IO-Code I could not directly see where the ... The effect on the device is not present on Linux, ... I will try an strace. ... in buffering none, ...
  • Re: LINUX vs AIX
    ... t% Subject: Re: LINUX vs AIX ... For small and frequent file I/O you need to ... t%> spread the I/O accross as many drives as possible. ... A high ninety some thing percent of channel ...