Newsletter # 7 - Multithreading with pthreads in Swift Nov 1 2019
Hello,
This year Unix turns 50! You can check the website thatBell Labs created for the commemoration. I've always found these stories fascinating. I can only imagine how cool it would be to be part of the team that built something as impactful as Unix. I've always wanted to be part of a team of "scientists" that changes the futures. I remember reading Nerds 2.0.1 and getting sad that those times have already passed, but also enjoying the storytelling.
Good news is that it's never too late. For example, check John Willis. He is 60 and Just moved to Red Hat. I was listening to his interview in On-Call Nightmares Podcast, and thought, there is always time.
Ok, back to the present day. This week's post was about using pthreads in macOS using Swift. Nowadays, most people will jump directly to Grand Central Dispatch, but I think there is a lot to learn from threads and the way we used to handle multitasking. If you are interested here is the link:
https://rderik.com/blog/multithreading-with-pthreads-in-swift/
As always questions and feedback are welcomed.
Ok, time to enjoy the weekend. If you are in Latin America, you'll probably be celebrating some type of All Saints day. In Guatemala eating Fiambre. In Mexico celebrating Day of the Dead. In North America eating your Halloween candies. Wherever you are, have a lovely weekend.
Derik
Tip of the Week
If you are searching for /usr/includes/ you won't find it there. Since Xcode 10 (check release notes), the system headers will be in the SDK. So if you want to check any of the system headers you can use the following command:
1
$ cd `xcrun --show-sdk-path`/usr/include
I was searching for syscall_sw.h, which is not there. I wonder why Apple removed it. Anyways, I had to check the XNU repo to find this file:
syscall_sw.h
This is the reason the system calls in assembler start with a 2!
1
2
3
4
5
6
#define SYSCALL_CLASS_NONE 0 /* Invalid */
#define SYSCALL_CLASS_MACH 1 /* Mach */
#define SYSCALL_CLASS_UNIX 2 /* Unix/BSD */
#define SYSCALL_CLASS_MDEP 3 /* Machine-dependent */
#define SYSCALL_CLASS_DIAG 4 /* Diagnostics */
#define SYSCALL_CLASS_IPC 5 /* Mach IPC */
The system calls are classified by a number, and the Unix/BSD starts with 2. That's why when we want to load that system call in assembler we use 0x2000001:
1
2
3
4
5
6
7
global _main
segment .text
_main:
mov eax, 0x2000001 ; AUE_EXIT x2000001 for macOS/BSD
mov edi, 1001b ; the status value to return
syscall ; execute ta system call
end
Dustin Schultz - was the one that found that out. So thanks Dustin.