stack related question in microprocessor - microprocessors

can we also do queue operations in microprocessor? (given that the microprocessor supports stack operations )

No. The stack is built in insofar as there's a register and operations to support it. There is no similar support for a queue.
If you want a queue, you need to implement it in code.

Have stack, want Queue??...
You can always implement queues in software. Refer this Q for more:
StackOverflow.com/questions/69192/using-stack-as-queue
For a detailed discussion on how to implement a queue using stacks:
GeeksforGeeks.org/?p=5009
GoodLUCK!!

Related

Difference between Thread, Isolate and Process in Dart

What's the difference between Thread, Isolate and a Process in Dart?
As far as I know Dart is a single-threaded language, but it can spawn many isolates which don't share memories with each other and we can do the heavy lifting work on them and return the result without blocking the UI.
But what Process is for, is that a part of an Isolate? Can anyone describe above three in more detail.
And when we do asynchronous programming using Future and let's see we are doing heavy lifting in it, will that block the UI thread in case it is awaited using the await keyword.
A Process is a native OS (Unix, Windows, MacOS) construct, which consists of one or more threads with their own address space and execution environment. In Dart, an application consists of one or more threads, one of which is the main UI thread, while the rest are typically called Isolates.
In contrast to what the previous answer said, All Dart code runs in an isolate.
Actually, your understanding is correct, based on what you said in the comments.
From the docs (emphasis mine):
Within an app, all Dart code runs in an isolate. Each Dart isolate has
a single thread of execution and shares no mutable objects with other
isolates. To communicate with each other, isolates use message
passing. Although Dart’s isolate model is built with underlying
primitives such as processes and threads that the operating system
provides, the Dart VM’s use of these primitives is an implementation
detail that this page doesn’t discuss.
Many Dart apps use only one isolate (the main isolate), but you can
create additional isolates, enabling parallel code execution on
multiple processor cores.
Your question hasn't been answered yet, and it will not be answered easily, because it depends on the language implementation.
Also, your another question: "And when we do asynchronous programming using Future and let's see we are doing heavy lifting in it, will that block the UI thread in case it is awaited using the await keyword."
-> Yes, it will block the UI, unless you use another isolate.

what is detatch & non-detatch threads in iPhone

Whats the difference between detach and non-detach thread in iPhone?
The iPhone "Threading Programming Guide" documentation says that
By default the NSThread class creates detach threads
And it also says that a Detached thread means that the thread's resources are automatically reclaimed by system when the thread exits. In the same way , how does it happen in non-detach threads?
Thank You.
Suse
This relates to the underlying pthread implementation. Read up on pthread_detach and pthread_join to understand the differences.
In practice, you probably don't care and Cocoa/NSThread do the right thing for you automatically.
And to clarify, there's no way to create a non-detached thread using NSThread. You'd have to use the low-level thread API for that.

Advice sought on using NSOperationQueue in IPhone ap

Should an IPhone app generally only use one shared NSOperationQueue, stored in maybe the app delegate, and have each controller put NSOperations into it as needed, or is it ok for each each controller to have its own NSOperationQueue? Are both approaches acceptable?
After skimming through the Concurrency Programming Guide, it looks like both approaches are safe and reasonable. The only consideration I could find that tends towards one over the other is this quote:
If your application has multiple
operation queues, each prioritizes its
own operations independently of any
other queues. Thus, it is still
possible for low-priority operations
to execute before high-priority
operations in a different queue.
If you're concerned about a large number of operations having priority conflicts, then it's probably best to use a single queue to make sure that your priorities take maximum effect. Otherwise, whichever makes more sense in the context of your code is just fine.

How does multithreading work in Objective-C on the iPhone?

I'm confused about the concept of "threads" in iPhone development:
Why are threads necessary / useful?
How can threads be used in Objective-C?
You need multi-threading in objective c because sometimes you need functions/code to run "in the background" (read: on another thread). For instance (but not explicitly) you might need to download large amounts of data off the internet (a picture, or a video).
In this case running the download on the 'main' thread will cause the iphone to freeze before the download is complete. So you use multi-threading to download the data AND let the iphone work all at the same time.
There are lots of ways to do multithreading in objective-c. To be honest you need to look it up yourself, we're not here to just spoonfeed you.
Things to look up are: NSURLConnection and the method [self performSelector:onThread:...]
More simple...If you want to run some methods(processes) parallely you can use threads...One thread is doing one stuff while another doing other stuff... So u can use threads if you need something to be done when another thing is doing...
Example: Thread 1: sending request to server
Thread 2: preparing information(image,text etc) to be sent.
So in general this is the purpose of threads
Recently, Apple suggests that programmers should move away from thread and use an alternative solution with more advantages, better performances and much more easier to implement; it's Concurrency Programming:
http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008091
The recommended way to implement concurrency is using queues.
For those who just want to execute a method / block in a separate thread - use this code:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
[self longMehtod];
});
for further information read the Concurrency Programming Guide from Apple

Running a socket stream in a thread

I have an application that opens a connection with 2 sockets (in and out) and I want to have them working in a thread.
The reason that I want them to be in a separate thread is that I don't want my application to freeze when I receive data, and this can happen anytime as long as the application is running.
Currently I have a class that handle also network communication and I run this class in an NSOperation, I'm not sure if it's the best solution.
I'm not very familiar with threading so guys if you could give me some help I would be very grateful.
Thanks
First, you should know that you can use the same socket to send and receive data — they're generally bi-directional. You should be able to share a reference to the same socket among multiple threads of execution.
Second, unless you'll be receiving large amounts of data and have experienced performance issues with your UI, I would delay optimizing for it. (Don't get me wrong, this is a good consideration, but premature optimization is the root of all evil, and simpler is generally better if it performs adequately.)
Third, NSOperation objects are "single-shot", meaning that once the main method completes, the operation task cannot be used again. This may or may not be conducive to your networking model. You might also look at NSThread. The fact that you already have the functionality "factored out" bodes well for your design, whatever turns out to be best.
Lastly, threading is a complex topic, but a good place to start (especially for Objective-C) is Apple's Threading Programming Guide.