Using system calls to create/context switch threads in assembly code
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Using system calls to create/context switch threads in assembly code
Hi all,
I am writing a compiler for a simple concurrent programming language. The compiler has to produce assembly code for Intel-32 architectures.
One of the major issue for code generation is how to create multithreaded assembly code. Linux provides system calls for creating threads, clone(,,,,). However, it seems there is no system call for doing context swiching for threads (is that so?). Also, our compiler has to deal with synchronizations among threads, so there should be a ready-queue that holds all ready-to-run threads and several waiting-queue. In order to do context swtiching, the compiler must be able to access each thread's CPU registers values (more specificly, the running thread's CPU register values need to be saved with the thread during context switching, so an array representing the CPU registers is needed to contruct a thread). I am not sure all of those are supported by the threads created with system calls.
Is it possible to construct a multi-threaded assembly program without making Linux system calls? Odd question, isn't? I do hope there is a solution.
Anyone has some suggestions?
Thanks
In the end, something will have to make a system call. As far as I know, glibc and libpthread don't have access to any secret API, so they have to manage what they do using system calls. Have you looked through the pthread sources? I haven't, but they are just a small add-on to glibc. Looks like about 7200 lines of code (using cat *.{c,h} | egrep -cv "(^$|^/\*)") for version 2.5, which isn't a whole lot to search through. In case you aren't aware, look for the linuxthreads package at most glibc ftp sites. The glibc functions with system call names are generally just wrapped system calls, so you can probably infer the correct system calls based on what libpthread does.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.