Monday, 26 August 2013

Multithreaded programming

In multithreaded programming, a thread is sometime required to block until some condition is true. In thread systems pre-dating Java, this mechanism is generally called "condition variables" and corresponds to a separately allocated object. For example using the pthread library, you do create and use a condition variable like this:
pthread_cond_t count_threshold_cv;
pthread_mutex_t count_mutex;
pthread_cond_wait(&count_threthold_cv, &count_mutex); // atomically unlock mutex while waiting
phtread_cond_signal(&count_threthold_cv);
When locks and condition variables are used together, the result is called a monitor:

  • A collection of procedures manipulating a shared data structure.
  • One lock must be held whenever accessing the shared data
  • One or more condition variables used for waiting.
In C#, there is no separate type for the condition variable. Instead every object inherently implements one condition variable, and the "Monitor" class provides static "Wait", "Pluse" and "PulseAll" methods to manipulate an object's condition variable. They are used together with lock or Monitor.Entor and Monitor.Exit.
public static KV GetFromList() {
  KV res;
  lock (typeof(KV)) {
    while (head == null) Monitor.Wait(typeof(KV));
    res = head; head = res.next;
    res.next = null; // for cleanliness
  }
  return res;
}

In C# every object also inherently implements a mutual exclusion lock.

Friday, 23 August 2013

Windows 7 shortcut


  • Win+Home: Clear all but the active window.P
  • Win+Space: All windows become transparent so you can see through to the desktop.P
  • Win+Up arrow: Maximize the active window.P
  • Shift+Win+Up arrow: Maximize the active window vertically.P
  • Win+Down arrow: Minimize the window/Restore the window if it's maximized.P
  • Win+Left/Right arrows: Dock the window to each side of the monitor.P
  • Shift+Win+Left/Right arrows: Move the window to the monitor on the left or right.
Source: