Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is concurrency done in Intel x86 assembly?

I'm curious to know how one would code concurrent software on Intel x86 assembly. Both threads or coroutines with yielding are interesting.

I realize this isn't practical to do in assembly, but I'm just curious.

like image 269
Tower Avatar asked Sep 05 '11 12:09

Tower


1 Answers

If you're talking about user space, the same way you do it in e.g. C. That is, you call pthread_create() (or whatever is the "create new thread" API on your OS) with appropriate arguments (including the address of the new thread's "main" function) and off you go.

If you're talking about bare-bones level without an OS to help you, then you'll allocate a block of memory (from the memory allocator you previously wrote) for the stack of your new thread, setup a periodic timer tick which runs (your previously written) scheduler code which saves register contents and switches between your thread stacks, etc.

As to how to do it with ASM instead of C? Well, except for a lot more sweat and tears, basically the same.

like image 175
janneb Avatar answered Sep 30 '22 04:09

janneb