Small task #2 and #2+

Write a program that uses threads without the help of the thread library (raw syscalls).

The program should:

  1. Create a new thread in the same address space – allocate the stack for the new thread, use syscall clone to run the code.
  2. In the new thread: write 1000 times "A\n" to the standard output (using syscall write), and then end the thread (syscall exit).
  3. In the main thread: write 1000 times "B\n" to the standard output (using syscall write), wait for the new thread to finish (waitpid) and then end the program (syscall exit_group).

The task can be done in two versions:

  • #2 (easy, worth 1 point): using the clone, syscall functions from libc.
  • #2+ (difficult, worth 2 points): not using any library functions, calling syscalls from assembly language.