Creating a thread VS Forking a thread
2008-01-22 11:21
323 查看
Thread *t;
char id[2], *name = "t";
int i, NumThreads = 4;
for(i=0;i<NumThreads;i++) {
sprintf(id,i);
strcat(name,id);
t = new Thread(name);
}
•creates 4 threads using the constructor function for the class Thread
•The constructor function simply allocates space for thread and sets its status to JUST_CREATED
•in Nachos, a "main" thread is created as part of system initialization
•the ready list remains empty upon creation of these threads.
•the global variable currentThread always points to the thread currently occupying the CPU
fork:
Thread *t;
char id[2], *name = "t";
int i, NumThreads = 4;
for(i=0;i<NumThreads;i++) {
sprintf(id,i);
strcat(name,id);
t = new Thread(name);
t->Fork("somefunction",0);
}
•Fork() allocates a stack for the thread which invokes it, and adds it to the ready list maintained by the scheduler
•StackAllocate() allocates and initializes the execution stack for the thread.
•A C routine ThreadRoot() is called which calls the function "somefunction" and upon its return, calls ThreadFinish().
•now, we have all four threads in the ready list with their status set to READY. currentThread still points to "main".
char id[2], *name = "t";
int i, NumThreads = 4;
for(i=0;i<NumThreads;i++) {
sprintf(id,i);
strcat(name,id);
t = new Thread(name);
}
•creates 4 threads using the constructor function for the class Thread
•The constructor function simply allocates space for thread and sets its status to JUST_CREATED
•in Nachos, a "main" thread is created as part of system initialization
•the ready list remains empty upon creation of these threads.
•the global variable currentThread always points to the thread currently occupying the CPU
fork:
Thread *t;
char id[2], *name = "t";
int i, NumThreads = 4;
for(i=0;i<NumThreads;i++) {
sprintf(id,i);
strcat(name,id);
t = new Thread(name);
t->Fork("somefunction",0);
}
•Fork() allocates a stack for the thread which invokes it, and adds it to the ready list maintained by the scheduler
•StackAllocate() allocates and initializes the execution stack for the thread.
•A C routine ThreadRoot() is called which calls the function "somefunction" and upon its return, calls ThreadFinish().
•now, we have all four threads in the ready list with their status set to READY. currentThread still points to "main".
相关文章推荐
- Using AfxBeginThread for multi-thread in VS C++
- (Vagrant Vs Docker)Should I use Vagrant or Docker for creating an isolated environment?
- Object sharing for Runnable vs. extends Thread
- Spring报错——Scope 'session' is not active for the current thread
- ChartFX for vs 2005 破解
- An Analytical Model for a GPU Architecture with Memory-level and Thread-level Parallelism Awareness
- C# - Recommendations for Abstract Classes vs. Interfaces
- How to install VS 2005 and MSDN for VS 2005 on XP without SP2
- Could not obtain transaction-synchronized Session for current thread
- FOR ALL ENTRIES vs DB2 JOIN 【翻译】
- [未解决]The connection pool for database has been unable to grant a connection to thread 1304
- MySQL: Your visual blueprint for creating open source databases
- getCurrentSession()时报错,no session found for current thread,解决方案
- Could not obtain transaction-synchronized Session for current thread 报错在spring注解定时任务上的处理
- Forking and executing process
- Creating a CAB file for your application
- Effective Use of Microsoft Enterprise Library: Building Blocks for Creating Enterprise Applications
- instancetype vs id for Objective-C
- vs编译项目报错:The OutputPath property is not set for this project
- Windows Azure Tools for VS2010新版本可用