Pasha Dimitri
About
-
Posted Answers
Answer
→ Concurrency : Concurrency is nothing but doing multiple jobs at the same time. It helps to write efficient, fast and super responsive code in a way doing more than one thing at a time. At the same time if we mis-used it, we will be tortured without having any mercy.
For Newbies or junior developers it might be a bit hard to achieve concurrency but once we learn it, it is easy to accomplish.
What is Concurrency?
In Computer Science, concurrency refers to the ability of different parts or units of a program, algorithm, or problem to be executed out-of-order or in partial order, without affecting the final outcome. This allows for parallel execution of the concurrent units, which can significantly improve overall speed of the execution in multi-processor and multi-core systems. In more technical terms, concurrency refers to the decomposability property of a program, algorithm, or problem into order-independent or partially-ordered components or units(wikipedia).
in Simple terms: Concurrency means that your application executes multiple streams (or threads) of operations all at the same time. This way the user interface stays responsive as you are performing your work other than main thread(main thread used to update the UI). UI will be refreshed for every 60 milli seconds, so it has high priority and should execute on main thread.
in iOS, we can achieve concurrency in two ways.
Operations are built on top of the GCD, so it is higher abstraction and easy to use. however in some cases we need to dig into the GCD, to avail of the benefits of it in order to get efficient way of working concurrency.
we will see how to work both of these in this tutorial.
Before Concurrency Code Snippet:
I used Image urls from https://unsplash.com/. With the following code, you will get your UI Freeze while scrolling the tableview because images are fetching on main thread. Main thread should always be free for UI activities. we solve this while going through forward in this tutorial.
→ Why do we need Concurrency :
Assume you are calling any web-service or doing some heavy work like getting an image from remote, applying some filters to that image before displaying it. If we do all these work on the main thread our APP’s UI will be freeze(Like the above example) to make it unresponsive to the users.
Users can not interact with the UI, so it gives bad experience. If we do all these things with the help of background threads, UI does not freeze on main thread, So user still can interact with our APP’s User Interface
2. Execution of Demanding Tasks in less time:
Executing high CPU demanding tasks on the background, APP’s UI is responsive and gives smoother experience to the users.
3. Utilise Device Hardware :
All iOS Devices are multi core processors that allows developers to execute multiple tasks parallel. If we not use it, it means we are wasting the provided resources.
While working on concurrency we face three problems, known as
The system provided APIs take care of the first two, we need to take care of the last one by using the APIs properly.
→ Task : A simple single piece of work that needs to be done.
→ Process : A process is an executable chunk of code that is made up of multiple threads. Simply it is nothing but a running program like your app, opening a safari pages, etc.
→ Thread : A concurrently running mechanism that executes multiple sets of instructions(Processes)
It contains a list of instructions (your code in Assembly format) and sits there on your disk until the user wishes to run it. The OS will then load that process into memory, start an instruction pointer that tells us which instruction of the program is currently being executed, and have the CPU sequentially execute its instructions until they end, terminating the process.Each process gets its own section of physical memory dedicated to itself. They do not share these addresses with other processes.
If a system has only one core, the system will switch between the threads that are currently executing(Using Time Multiplex Scheduling System), this is also called as ‘Context Switching’. if there are more than one core, the threads will be distributed among those cores for processing. As technology improves the hardware and computing powers gets better now. So we should take the advantages of these.
→ Grand Central Dispatch :
A Dispatch Queue will automatically create and reuse a pool of threads as it finds necessary, abstracting from you the hassle of spawning threads manually and dealing with potential issues of doing so.
We have two types of Dispatch Queues :
These two types execute the code in the other threads than the thread they were created on. Simply, These queues dispatch your blocks of code to other threads.
→ Serial Queues:
Serial Queues execute one task at a time. These are good to use when those tasks are required to use system resources. The tasks in one serial queue do not care about the other tasks in a separate serial queue.
We can use multiple serial queues so they can run parallel.
Example: A real world humans queue before a cinema, where one is served at a time. If every one(Thread) in the queue comes at a time to get the tickets it will be messy and the person at the counter(System Resource) does not know whom to serve and gets confused.
Advantages :
→ Concurrent Queues:
As the name suggests, Concurrent Queues allow to execute multiple tasks in parallel at the same time. The tasks start in the order in which they are added in the queue, but their execution will occur concurrently. These tasks do not have to wait each other to start.
In the concurrent queues, it is guaranty that the tasks start in the order, but we don’t know the order of execution, execution time or number of currently executing tasks at a time.
In a real world example, it is like human queues in a cinema booking counter, with more than one queue with multiple service counters. If there are 5 counters and five queues, 5 persons will be served at a time.
Answer is posted for the following question.
Answer
Acetone can be made dry by adding anhydrous magnesium sulfate to it The sulfate should be hot because it can easily absorb water from the atmosphere when cold
Answer is posted for the following question.
How to make anhydrous acetone?
Answer
You can contact Customer Care at 844-994-4646, via live chat at support.aainflight.com or by email at subscription.wifi@aa.com .
Answer is posted for the following question.
How to cancel american airlines wifi subscription?
Answer
- Method 1 Remove and connect back all hardware components
- Method 2 Check boot order
- Method 3 Reset primary partition as active
- Method 4 Check internal hard disk status
- Method 5 Fix boot information (BCD and MBR)
- Method 6 Recover deleted boot partition
Answer is posted for the following question.
How to fix no bootable device?
Answer
- Email us. Mailto: customercare.india@ikea.com.
- Chat with us. Initiate chat: Click here. Available from 9 am-9 pm.
- Call us. +91 1800 419 4532. Available from 9 am-9 pm.
Answer is posted for the following question.
How to call ikea store directly?
Answer
Hotel The Panache
Address: West of Ram Gulam Chowk, South Gandhi Maidan, Patna, Bihar 800001
Lemon Tree Premier, Patna
Address: Plot no, 876, Exhibition Rd, near Gandhi Maidan Road, South Gandhi Maidan, Raja Ji Salai, Dujra Diara, Patna, Bihar 800001
Answer is posted for the following question.
Where can I locate best Western Plus Jobs in Patna, Bihar?
Answer
- Airport Utility. After much deliberation, I've opted to discuss Airport Utility first.
- System Information.
- Activity Monitor.
- Keychain.
- Grab.
- Terminal.
- Migration Assistant.
Answer is posted for the following question.
What is utilities on i phone?