by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :) Computer Engineering Tips - Computer Engineering news and articles - Thread Creation Fundamentals Computer Engineering Tips - Computer Engineering news and articles - Thread Creation Fundamentals
  Home arrow Operating Systems arrow Fundamentals arrow Thread Creation Fundamentals
Computer Engineering Tips - Computer Engineering news and articles | _DATE_FORMAT_LC
 
 
Main Menu
Home
News
Algorithms
Artificial Intelligence
Bioinformatics
Computer Graphics
Computer Networks
Computer Organization
Computer Security
Data Mining
Data Structures
Database Systems
Distributed Computing
Internet
Operating Systems
Parallel Computing
Programming Languages
Publications
Robotics
Software Engineering
Other Articles


Partners

All Partners

 
 
 
Thread Creation Fundamentals _CMN_EMAIL
_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 

Threads, like processes, are a mechanism to allow a program to do more than one job at a time. As with processes, threads appear to run concurrently; the linux kernel schedules them asynchronously, interrupting each thread from time to time to give others a chance to execute.

Conceptually, a thread exists within a process. Threads are a finger grained unit of execution than processes. When you invoke a program, linux creates a new process and in that process creates a single thread, which runs the program sequentially. That thread can create additional threads; all these threads run the same program in the same process, but each thread may be executing a different part of the program at any given time.

Comparing a thread with process, when a program forks a child process the child process runs copying the memory and file descriptors from its parent. Parent’s memory, file descriptors etc can be modified by the child process without affecting parent and vice-versa. Though nothing is copied while creation of another thread. Same memory space and other system resources as the original are shared by the creating and the created thread. The modified value of a variable by one thread will be seen by the other thread. Similarly, reading and writing by other threads may not be possible to a file descriptor once it is closed by the thread. Because a process and all its threads can be executing only one program at a time, if any thread inside a process calls one of the exec functions, all the other threads are ended(the new program may, of course, create new threads.)

Thread Creation

Each thread in a process is identified by a thread id. Execution of a thread function takes place on creation of a thread. This is just an ordinary function and contains the code that the thread should run. When a function returns, thread exits. On GNU/Linux passes the value along to the thread without looking at it. User’s program can use this parameter to pass data to a new thread. Similarly, the program can use the return value to pass data from an exiting thread back to its creator.

The pthread_create function creates a new thread. This function needs to be provided with the following:

  • A pointer to the pthread_t variable, in which the thread id of the new thread is stored.
  • A pointer to a thread attribute object. This object controls details of how the thread interacts with the rest of the program. If NULL is passed as the thread attribute, a thread will be created with the default thread attributes.
  • A pointer to the thread function. This is an ordinary function pointer of this type:
  • Void* (*)(void*)

  • A thread argument value of type void*. Whatever you passed is simply passed as the argument to the thread function when the thread begins executing.

A call to pthread_create returns immediately, and the original thread continues executing the instructions following the call. Execution of the new thread function begins in the meantime. Although scheduling of both the threads takes place asynchronously, and your program must not rely on the relative order in which instructions are executed in the two threads.

Under normal circumstances, a thread exits in one of the two ways. One way is by returning from the thread function. The return value from the thread function is taken to be the return value of the thread. Alternately, a thread can exit explicitly by calling pthread_exit. This function may be called from within the thread function or from some other function called directly or indirectly by the thread function. The argument to pthread_exit is the thread’s return value.

 
 Sponsored Links

_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 
_ITEM_PREVIOUS   _ITEM_NEXT
 
       
         
     
 
Advertisement
 
   

Copyright 2005 - 2006 Science Tips Team. All rights reserved.

Nanotechnology Development Blog