Multithreading Part I: Multithreading and Multitasking

Multithreading Part I: Multithreading and Multitasking

In this and a series of articles that would follow, we would learn about threads and how to write multi-threaded programs in C#. 

In this article we would learn what threads are and why they are needed. In part2 we would learn about threading with respect to the .NET framework. At the end of this article series you would have learnt how to create and manage threads, set thread priorities, determine thread states, thread pooling and thread synchronization.

Introduction

When the computers were first invented, they were capable of executing one program at a time. Thus once one program was completely executed, they then picked the second one to execute and so on. With time, the concept of timesharing was developed whereby each program was given a specific amount of processor time and when its time got over the second program standing in queue was called upon (this is called Multitasking, and we would learn more about it soon). Each running program (called the process) had its own memory space, its own stack, heap and its own set of variables. One process could spawn another process, but once that occurred the two behaved independent of each other. Then the next big thing happened. The programs wanted to do more than one thing at the same time (this is called Multithreading, and we would learn what it is soon). A browser, for example, might want to download one file in one window, while it is trying to upload another and print some other file. This ability of a program to do multiple things simultaneously is implemented through threads (detailed description on threads follows soon).

Multitasking vs. Multithreading

As explained above, Multitasking is the ability of an operating system to execute more than one program simultaneously. Though we say so but in reality no two programs on a single processor machine can be executed at the same time. The CPU switches from one program to the next so quickly that appears as if all of the programs are executing at the same time. Multithreading is the ability of an operating system to execute the different parts of the program, called threads, simultaneously. The program has to be designed well so that the different threads do not interfere with each other. This concept helps to create scalable applications because you can add threads as and when needed. Individual programs are all isolated from each other in terms of their memory and data, but individual threads are not as they all share the same memory and data variables. Hence, implementing multitasking is relatively easier in an operating system than implementing multithreading.

Hey, wait!!! all that’s fine but I still do not understand fully what threads are!!!

Understanding Threading in .NET Framework

Understanding Threading in .NET Framework

Summary

Thread basics using followings:

  • How to Create thread; use System.Thread() class and create an instance

  • How to Join thread; use object.Join() to join threads.

  • How to Suspend thread; use object.Sleep(<No of seconds>) to Suspend thread

  • How to Kill thread; use object.Abort() to Suspend thread

  • Using Interlocked class which uses Increment and decrement method to increment and decrement values.

Thread Synchronization using followings:

  • Using Locks: allows to mark a lock on the critical section of the code(program), provides synchronization to an object and then to execute the lock is in effect.

  • Using Monitor: allows to decide when to enter and exit the synchronization, and it lets us wait for another area of code to become free. Monitor acts as a smart lock on a resource. When the we need synchronization, we can call the enter() method of the monitor passing the object we want to monitor. We can explicitly choose to wait () method of the monitor to control thread ordering. In case of using wait () waiting threads will be allowed to notified of a chance to run again if the active thread calls Pulse (). This signals the CLR that there has been a chance in the state that might free a thread that is waiting. The CLR tracks of the fact that the earlier thread asked to wait, and the thread will be guaranteed access in the order in which the wait where requested. Exit () can be called once when the thread is finished with the monitor.

Introduction to Multithreading in C#

Introduction to Multithreading in C#

ceases

Introduction to Multithreading in C#

In working in New York and talking to programmers all over Wall Street, I’ve noticed a common thread of knowledge expected in most real time programming applications.  That knowledge is known as multithreading.  As I have migrated around the programming world, and performed interviews on potential programming candidates, it never ceases to amaze me how little is known about multithreading or why or how threading is applied.  In a series of excellent articles written by Vance Morrison, MSDN has tried to address this problem:  (See the August Issue of MSDN, What every Developer Must Know about Multithreaded Apps,  and the October issue Understand the Impact of Low-Lock Techniques in Multithreaded Apps. Also there are many articles here on C# Corner on threading such as Understanding Threading in the .NET Framework by Chandrakant Parmar or the four part series by Manisha Mehta: Multithreading Part 1: Multithreading and Multitasking,    Multithreading Part 2: Understanding the System.Threading.Thread ClassMultithreading Part 3: Thread Synchronization, and Multithreading Part 4: The ThreadPool, Timer Classes and Asynchronous Programming Discussed.

In this article I will attempt to give an introductory discussion on threading, why it is used, and how you use it in .NET.  I hope to once and for all unveil the mystery behind multithreading, and in explaining it, help avert potential threading disasters in your code.

cryptlib

cryptlib – Wikipedia, the free encyclopedia

cryptlib

From Wikipedia, the free encyclopedia

Jump to: navigation, search

 

 

cryptlib
Developer(s) Peter Gutmann
Initial release 1995 (1995)
Stable release 3.4.1 / July 27, 2011; 12 months ago (2011-07-27)[1]
Programming language used C
Operating system Cross-platform
Type Security library
License Sleepycat License
Website www.cs.auckland.ac.nz/~pgut001/cryptlib/

cryptlib is an open source cross-platform software security toolkit library. It is distributed under the Sleepycat License, a free software license compatible with the GNU General Public License. Alternatively, cryptlib is available under a standard commercial license for those preferring to use it under commercial terms.[2]

Contents

 [hide

[edit] Features

cryptlib is a security toolkit library that allows programmers to incorporate encryption and authentication services to software. It provides a high-level interface so strong security capabilities can be added to an application without needing to know many of the low-level details of encryption or authentication algorithms. It comes with an over 400 page programming manual.[3]

At the highest level, cryptlib provides implementations of complete security services such as S/MIME and PGP/OpenPGP secure enveloping, SSL/TLS and SSH secure sessions, CA services such as CMP, SCEP, RTCS, and OCSP, and other security operations such as secure timestamping. Since cryptlib uses industry-standard X.509, S/MIME, PGP/OpenPGP, and SSH/SSL/TLS data formats, the resulting encrypted or signed data can be easily transported to other systems and processed there, and cryptlib itself runs on many operating systems—all Windows versions and most Unix/Linux systems. This allows email, files, and EDI transactions to be authenticated with digital signatures and encrypted in an industry-standard format.

cryptlib provides other capabilities including full X.509/PKIX certificate handling (all X.509 versions from X.509v1 to X.509v4) with support for SET, Microsoft AuthentiCode, Identrus, SigG, S/MIME, SSL, and Qualified certificates, PKCS #7 certificate chains, handling of certification requests and CRLs (certificate revocation lists) including automated checking of certificates against CRLs and online checking using RTCS and OCSP, and issuing and revoking certificates using CMP and SCEP. It also implements a full range of certification authority (CA) functions provides complete CMP, SCEP, RTCS, and OCSP server implementations to handle online certificate enrolment/issue/revocation and certificate status checking. Alongside the certificate handling, it provides a sophisticated key storage interface that allows the use of a wide range of key database types ranging from PKCS #11 devices, PKCS #15 key files, and PGP/OpenPGP key rings through to commercial-grade RDBMS‘ and LDAP directories with optional SSL protection.

The First Few Milliseconds of an HTTPS Connection

Moserware: The First Few Milliseconds of an HTTPS Connection

The First Few Milliseconds of an HTTPS Connection

Convinced from spending hours reading rave reviews, Bob eagerly clicked “Proceed to Checkout" for his gallon of Tuscan Whole Milk and…

Whoa! What just happened?

In the 220 milliseconds that flew by, a lot of interesting stuff happened to make Firefox change the address bar color and put a lock in the lower right corner. With the help of Wireshark, my favorite network tool, and a slightly modified debug build of Firefox, we can see exactly what’s going on.

By agreement of RFC 2818, Firefox knew that “https" meant it should connect to port 443 at Amazon.com:

socketSniff

SocketSniff v1.08
Copyright (c) 2008 – 2012 Nir Sofer

 

Related Utilities

  • SmartSniff – Capture TCP/IP packets on your network adapter

 

Description

SocketSniff allows you to watch the Windows Sockets (WinSock) activity of the selected process.
For each created socket, the following information is displayed: socket handle, socket type, local and remote addresses, local and remote ports, total number of send/receive bytes, and more. You can also watch the content of each send or receive call, in Ascii mode or as Hex Dump.

 

System Requirements

This utility works on Windows 2000, Windows XP, Windows Server 2003, Windows Server 2008, Windows Vista, and Windows 7 (32-bit only). Older versions of Windows are not supported. On x64 version of Windows, SocketSniff can only work with 32-bit programs.

 

Warning !

Do not use this tool to debug smss.exe process under Windows 7, because from unknown reason, it causes a blue screen of death.

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way | Demystifying The Code

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

Decrypting SSL traffic using Wireshark – Tom Decaluwé

Decrypting SSL traffic using Wireshark

Decrypting SSL traffic using Wireshark – Tom Decaluwé

Decrypting SSL traffic using Wireshark

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way | Demystifying The Code

Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

Supporting multiple sites with a single SSL Certificate « Binarymist

Using the appcmd utility

We now add the https binding and host information to our sites that need to share the wild card certificate.

Run a command prompt as administrator and

 

cd to %WINDIR%\system32\inetsrv

 

The format of the command looks like the following:

 

appcmd set site /site.name:"<your website name>" /+bindings.[protocol='https',bindingInformation='*:443:<your ssl domain>']

 

For our above three sites we wanted to use the same certificate,
mysane.site.com, myinsane.site.com, mycrazy.site.com
They may be named respectively:
mysane, myinsane, mycrazy
So for example,
we’d run the following commands:

 

appcmd set site /site.name:"mysane" /+bindings.[protocol='https',bindingInformation='*:443:mysane.site.com']

 

You should get feedback similar to the following:

 

SITE object "mysane.site.com" changed

 

if all goes well

 

appcmd set site /site.name:"myinsane" /+bindings.[protocol='https',bindingInformation='*:443:myinsane.site.com']

 

You should get feedback similar to the following:

 

SITE object "myinsane.site.com" changed

 

if all goes well

 

appcmd set site /site.name:"mycrazy" /+bindings.[protocol='https',bindingInformation='*:443:mycrazy.site.com']

 

You should get feedback similar to the following:

 

SITE object "mycrazy.site.com" changed

 

if all goes well

Although I normally keep it simple and name my sites the same as the URL (your ssl domain) I want to use.

IIS 6

Now this is a bit more work than with IIS 7.

If it’s not already installed, you’ll need the SelfSSL tool.
You can get this from the SSL Diagnostics Kit or the IIS 6.0 Resource Kit which contains lots of other stuff.
Once installed, run IIS.

Create the self signed wildcard certificate

You’ll need to generate the certificate for one existing IIS site.
For the first site take note of the site idendifier.
You can see this in the right pane when you select Web Sites from the server node in the IIS manager.
Open a command prompt, you’ll need to run the SelfSSL app.
Actually I think the easiest way to run this is Start menu -> All Programs -> IIS Resources -> SelfSSL -> SelfSSL.
The command string looks like this:

 

selfssl /n:cn=<your wild card domain> /s:<first website identifier> /P:<port you want to use> /v:<number of days to expiration>

 

So for example, we’d run the following command:

 

selfssl /n:cn=*.site.com /s:1 /P:443 /v:365

 

Options for SelfSSL

 

selfssl /?

 

some of them are:

/N: – This specifies the common name of the certificate. The computer name is used if there is no common name specified.
/K: – This specifies the key length of the certificate. The default is length 1024.
/V: – This specifies the amount of time the certificate will be valid for, calculated in days. The default setting is seven days.
/S: – This specifies the Identifier of the site, which we obtained earlier. The default will always be 1, which is the Default Web Site in IIS.

Assign the certificate to the sites that need it

Have a look at the site properties in IIS Manager -> Directory Security tab -> Server Certificate button.
This will start the IIS wizard.
Click Next -> Assign an existing certificate -> Next.
You should see the wild card certificate you created.
Select it, click next, and make sure you assign it the same port that was assigned to the first site.

Configure the SecureBindings

In order for IIS to use the host headers with SSL and secure the certificate as we did with appcmd,
you’ll need to run the following command for each of the sites that require it.
My adsutil is found in C:\Inetpub\AdminScripts\
It’s probably not in your path, so you’ll have to run it from location.
cscript adsutil.vbs set /w3svc/<website identifier>/SecureBindings ":443:<your ssl domain>"

 

So for example, we’d run the following command:
cscript adsutil.vbs set /w3svc/1/SecureBindings ":443:mysane.site.com"

 

That should be it.

Now if you need to remove a certificate from your store

Run mmc.exe
File menu -> Add/Remove Snap-in… -> Add… -> select Certificates -> Add -> select Computer account -> Next -> select Local computer -> Close -> Ok.
Select the Certificates node, expand Personal, Certificates.
Now in the right window pane, you can manage the certificates.
Delete, Renew etc.