What is NSManagedObjectContext’s performBlock: used for?

The methods performBlock: and performBlockAndWait: are used to send messages to your NSManagedObjectContext instance if the MOC was initialized using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType. If you do anything with one of these context types, such as setting the persistent store or saving changes, you do it in a block. performBlock: will add the block to the … Read more

How to create a sleep/delay in nodejs that is Blocking?

Node is asynchronous by nature, and that’s what’s great about it, so you really shouldn’t be blocking the thread, but as this seems to be for a project controlling LED’s, I’ll post a workaraound anyway, even if it’s not a very good one and shouldn’t be used (seriously). A while loop will block the thread, … Read more

How would you implement a basic event-loop?

I used to wonder a lot about the same! A GUI main loop looks like this, in pseudo-code: void App::exec() { for(;;) { vector<Waitable> waitables; waitables.push_back(m_networkSocket); waitables.push_back(m_xConnection); waitables.push_back(m_globalTimer); Waitable* whatHappened = System::waitOnAll(waitables); switch(whatHappened) { case &m_networkSocket: readAndDispatchNetworkEvent(); break; case &m_xConnection: readAndDispatchGuiEvent(); break; case &m_globalTimer: readAndDispatchTimerEvent(); break; } } } What is a “Waitable”? Well, it’s … Read more

What’s the difference between: Asynchronous, Non-Blocking, Event-Base architectures?

Asynchronous Asynchronous literally means not synchronous. Email is asynchronous. You send a mail, you don’t expect to get a response NOW. But it is not non-blocking. Essentially what it means is an architecture where “components” send messages to each other without expecting a response immediately. HTTP requests are synchronous. Send a request and get a … Read more

Is non-blocking I/O really faster than multi-threaded blocking I/O? How?

The biggest advantage of nonblocking or asynchronous I/O is that your thread can continue its work in parallel. Of course you can achieve this also using an additional thread. As you stated for best overall (system) performance I guess it would be better to use asynchronous I/O and not multiple threads (so reducing thread switching). … Read more

How efficient is locking and unlocked mutex? What is the cost of a mutex?

I have the choice in between either having a bunch of mutexes or a single one for an object. If you have many threads and the access to the object happens often, then multiple locks would increase parallelism. At the cost of maintainability, since more locking means more debugging of the locking. How efficient is … Read more

asynchronous and non-blocking calls? also between blocking and synchronous

In many circumstances they are different names for the same thing, but in some contexts they are quite different. So it depends. Terminology is not applied in a totally consistent way across the whole software industry. For example in the classic sockets API, a non-blocking socket is one that simply returns immediately with a special … Read more

tech