===================================
Thread life
1. thread state
contain four statuses and each status may contain some substate.
The basic-state: 1. Ready 2. Running 3. Blocked 4. Terminated
Note: the state will decise the the scheudle of the thread.
Terminated stated:
when detached, thread is immediately recycled. But when non-detached, the terminted state will be remained untill it joined or detached.
2. creation..
Note: In system of supporting thread, no code could run without a thread. The first thread is created by system, and additional thread should be created by explict calls.
And the create function has no synchronization machincism. So the thread maybe run before the function returning.
3. Starting..
In gernal, the start function of the process ( main thread ) is called from outside your programm, it usually link a file called crt0.o, then the main call will be called. And other thread will start at the thread function address.
And another thing shouled be noted, is that thread terminate. If the main thread is terminated using return, the other thread will be terminated immediatedly. If want the other thread still run after the main thread exit, could use the pthread_exit to terminate the main thread.
4. Running and block
5. termination
阅读(863) | 评论(0) | 转发(0) |