Amazon Interview Question
Software Engineer / DevelopersCountry: India
Well, you're right that it should probably depend on whether the data is completely independent or shared across the 3 processes.
I don't know so much about the efficiency difference. I think some OSes implement threads and processes in much the same way. In any case, it's definitely an OS-specific detail.
I would ask here what's the architecture of the system. If it uses a CPU having multiple cores then I would prefer the separate threads implementation. But if its a single core CPU I would go for a multi-threaded implementation.It is because the thread switch overhead is much less than that of a process switch.
i told him that if i will use process then at a time i will use one process when it will completed then i will swap with another process.lets assume that if one task is taking 4bytes memory then in this way i will able to complete my task in only 4 bytes. but if i use 3 threads within one process then i have to use 12 bytes . then he told me lets assume you have lot of space.then which you would prefer.
Hi,
I would choose threads. As they are more efficient. Tasks can be completed in shorter period of time.
k lets assume if two of them want to access same data at a time. means if you thread A want to access some data D. and thread B want to access data D at that time. then their would be conflict between them.
The cost of spawning a thread is much cheaper than creating a separate process.
Create a process when you want a part of your system to run independently, such as something that provides a service. You can still communicate with IPC ( inter process communication ). But if you want to speed up your program and sharing some data, address space..use threads.
this is what i think...
- Anonymous February 04, 2012threads are useful when they share some variables or address space..thus context switching between them is more efficient as compared to between processes...
thus implementing multiple threads in the given case would prove useful only when the tasks have some variables shared..if they are completely independent of each other..there is no difference between using seperate processes or seperate memory...
also multithreading would be favoured in case of uniprocessor arhitecture while multiprocessing in multiprocessor as already mentioned in the post of Preetam..
correct me if i am wrong.
Thanks.