Skip to content

Instantly share code, notes, and snippets.

View luisdeol's full-sized avatar
🎯
Focusing

Luis Felipe de Oliveira luisdeol

🎯
Focusing
View GitHub Profile
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 14:38
Using the Parallel Class
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Priting Even numbers using Parallel.For");
Parallel.For(0, 10, i =>
{
if (i % 2 == 0)
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 14:38
Using the Parallel Class
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Priting Even numbers using Parallel.For");
Parallel.For(0, 10, i =>
{
if (i % 2 == 0)
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 14:46
Using the async and await keywords
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
string objectText = DownloadContentFromApi(1).Result;
Console.WriteLine(objectText);
Console.ReadLine();
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 14:55
Using PLINQ: AsParallel
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
var aLotOfNumbers = Enumerable.Range(0, 100);
var parallelEvenNumbers = aLotOfNumbers
.AsParallel()
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 14:59
Using PLINQ: AsOrdered
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
var aLotOfNumbers = Enumerable.Range(0, 100);
var parallelEvenNumbers = aLotOfNumbers
@luisdeol
luisdeol / Program.cs
Created November 12, 2017 15:05
Using PLINQ: ForAll
namespace MultiThreadingExamples
{
class Program
{
static void Main(string[] args)
{
var anIncrediblyBigSet = Enumerable.Range(0, 10);
var parallelEvenNumbers = anIncrediblyBigSet
.AsParallel()
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 18:07
Problems when accessing shared data using multithreading programming
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
int theAlmightyZero = 0;
Task newAmazingTask = Task.Run(() =>
{
@luisdeol
luisdeol / Program.cs
Created November 19, 2017 18:17
Using the lock operator
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
int theAlmightyZero = 0;
object _lockTheSavior = new object();
Task newAmazingTask = Task.Run(() =>
@luisdeol
luisdeol / Program.cs
Last active November 19, 2017 18:37
Example of deadlock using lock
namespace manage_multithreading
{
class Program
{
static void Main(string[] args)
{
object _lockSaviorOne = new object();
object _lockSaviorTwo = new object();
Task leTask = Task.Run(() =>
@luisdeol
luisdeol / VolatileExample.cs
Created November 19, 2017 19:07
Example of a situation where Volatile can be used.
private static int _theFlag;
private static int _theValue;
public static void TheFirstThread()
{
_theValue = 10;
_theFlag = 1;
}
public static void TheSecondThread()
{