title: Is it possible to create threads without system calls in Linux x86 GAS assembly?
body: <p>Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using <a href="http://www.ibm.com/developerworks/linux/library/l-system-calls/" rel="noreferrer">system calls</a>. These system calls come in very handy and are sometimes even necessary as your program <a href="http://en.wikipedia.org/wiki/Kernel_mode#Supervisor_mode" rel="noreferrer">runs in user-space</a>.<br>
  However system calls are rather expensive in terms of performance as they require an interrupt (and of course a system call) which means that a context switch must be made from your current active program in user-space to the system running in kernel-space.</p>
  
  <p>The point I want to make is this: I'm currently implementing a compiler (for a university project) and one of the extra features I wanted to add is the support for multi-threaded code in order to enhance the performance of the compiled program. Because some of the multi-threaded code will be automatically generated by the compiler itself, this will almost guarantee that there will be really tiny bits of multi-threaded code in it as well. In order to gain a performance win, I must be sure that using threads will make this happen.</p>
  
  <p>My fear however is that, in order to use threading, I <em>must</em> make system calls and the necessary interrupts. The tiny little (auto-generated) threads will therefore be highly affected by the time it takes to make these system calls, which could even lead to a performance loss...</p>
  
  <p><strong>my question is therefore twofold (with an extra bonus question underneath it):</strong>  </p>
  
  <ul>
  <li>Is it possible to write assembler
  code which can run multiple threads
  simultaneously on multiple cores at
  once, <em>without</em> the need of system
  calls?</li>
  <li>Will I get a performance gain if I have really tiny threads (tiny as in the total execution time of the thread), performance loss, or isn't it worth the effort at all?</li>
  </ul>
  
  <p>My guess is that multithreaded assembler code is <em>not</em> possible without system calls. Even if this is the case, do you have a suggestion (or even better: some real code) for implementing threads as efficient as possible?</p>