LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2007, 11:02 PM   #1
casmac
Member
 
Registered: Aug 2006
Distribution: SUSE 10
Posts: 31

Rep: Reputation: 15
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

tony
 
Old 07-13-2007, 04:48 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Context switch arunachalam Linux - General 3 06-15-2009 01:21 PM
measuring context switch time between two threads sekhar Programming 1 06-01-2007 07:16 AM
Thread context switch causes lost interrupt EmbeddedSteve Linux - Kernel 1 09-01-2006 03:45 PM
Create new from context menu johnnydangerous Fedora 3 02-07-2005 04:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration