Operating System - HP-UX
1833793 Members
2895 Online
110063 Solutions
New Discussion

Re: problem about performance

 
Victor.Lin
Occasional Contributor

problem about performance

Thread A writes data into a queue which can be devided into N slots,

thread B read from it.
If two semaphores of value 1 are associated with the queue, one for

full and one for empty, then A and B can access the queue multual

exclusively. On double CPU machine, this program has low performance.
If two semaphores of value N are associated with the queue, one for

full slots and one for empty slots, A and B can access the queue

simultaneously. But if B sem_wait(fcnt) and block, then A write data

into the queue. At this time, B is runnable and waked up. Each time A

write a data slot into the queue, context switch may occurs. It wastes

a lot of CPU time.
How can I design the program so that the two threads can run

simultaneously to use the two CPU, at the same time, context switch is

not frequently ?
By the way, do I need to do something such as binding threads into

individual CPU so that two threads can run simultaneously to use the

two CPU ?
2 REPLIES 2
Praveen Bezawada
Respected Contributor

Re: problem about performance

Hi
Performance of your program will improve if the threads are made to run different CPU.
You can make use of the mpctl function in C to make the threads run on different CPU's
it is used as
mpctl(MPC_SETLWP,cpu,lwpid)

Check man mpctl
Hope this helps...

...BPK...
Victor.Lin_1
Occasional Advisor

Re: problem about performance

Why I could not find the button th assign the point ?
I am very sorry.