Professional Documents
Culture Documents
CELF ELC Europe 2009: On Threads, Processes and Co-Processes
CELF ELC Europe 2009: On Threads, Processes and Co-Processes
On Threads,
Processes and
Co-Processes
Gilad Ben-Yossef
Codefidence Ltd.
I/O memory 3
Process 0 Process1
I/O memory 2
0x00000000
I/O memory 1 0x00000000
0xFFFFFFFFF
Memory
RAM 1 Management All the processes have
Unit their own virtual
RAM 0 Process2
address space, and run
as if they had access to
0x00000000
the whole address
0x00000000 space.
Read Only
Execute
Non Cached
Memory
CPU MMU
Bus
Task 2
Can set task size 1. Perform
and number of tasks calculation on a
variable size array
1.85 1.83
1.81 1.81
Context Switch Time in Usec
1.8
1.76
1.75 1.74
Threads
1.7 1.69 Proccesses
1.65
1.6
5 10 20
Number of Threads/Processes
2.24
2.23
2.23
Context Switch Time in Usec
2.23
2.22 2.22 2.22
2.22
2.22
2.21
2.21 Threads
2.21 Proccesses
2.2
2.2
2.2
2.19
2.19
5 10 20
Number of Threads/Processes
18 16.61
15.85
16
Context Switch Time in Usec
14
12
10
Threads
8 Proccesses
6
3.73 3.28
4
1.99 1.92
2
0
5 10 20
Number of Threads/Processes
4
3.44
3.5 3.24 3.26
Context Switch Time in Usec
3.05
3
2.61
2.5 2.36
2 Threads
Proccesses
1.5
1
0.5
0
5 10 20
Number of Threads/Processes
20
17.77 17.87
18
Context Switch Time in Usec
16
14.25
14 13.18 13.7 13.35
12
10 Threads
8 Proccesses
6
4
2
0
5 10 20
Number of Threads/Processes
250
222.41227.63 227.68228.23
Context Switch Time in Usec
200
178.06
167.88
150
Threads
100 Proccesses
50
0
5 10 20
Number of Threads/Processes
fork() pthread_create()
Zero parameters. Can specify most
Set everything yourself attributes for new
after process creation. thread during create
New process begins
Can specify function
with a virtual copy of for new thread to
parent at same location start with
Copy on write semantics
Easy to grasp
require shared memory address space
setup sharing
Processes Threads
PID visible in the No way to name task
system. in a unique name.
Can set process Kernel thread id not
name via related to internal
program_invocation_n thread handle.
ame. Difficult to ID a thread
Easy to identify a in the system.
processes in the
system.
int coproc_init(size_t shm_max_size);
pid_t coproc_create(char * coproc_name, struct
coproc_attributes * attrib, int flags, int (*
start_routine)(void *), void * arg);
int coproc_exit(void);
void * coproc_alloc(size_t size);
void coproc_free(void * ptr);
int coproc_join(pid_t pid, int * status);
coproc_init(1024 * 1024);
test_mem = coproc_alloc(1024);
if(!test_mem) abort();
pid = coproc_create("test_coproc", &test_coproc_attr, \
COPROC_SHARE_FS ,test_coproc_func, test_mem);
if(pid < 0) abort();
coproc_join(pid, &ret);
coproc_free(test_mem);
Questions?
Codefidece Ltd.: http://codefidence.com
Community site: http://tuxology.net
Email: gilad@codefidence.com
Phone: +972-52-8260388
Twitter: @giladby
SIP: gilad@pbx.codefidence.com
Skype: gilad_codefidence
(C) 2008,2009 Codefidence