Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>TP.ConcurrentProgramming.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>TP.ConcurrentProgramming.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

</Project>
17 changes: 17 additions & 0 deletions ConcurrentProgramming/CommonDataConsistency/CriticalSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

//____________________________________________________________________________________________________________________________________
//
// Copyright (C) 2024, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community by pressing the `Watch` button and get started commenting using the discussion panel at
//
// https://github.com/mpostol/TP/discussions/182
//
//_____________________________________________________________________________________________________________________________________

namespace TP.ConcurrentProgramming.CommonDataConsistency
{
public class CriticalSection
{
}
}
11 changes: 11 additions & 0 deletions ConcurrentProgramming/Communication/Communication.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>TP.ConcurrentProgramming.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>TP.ConcurrentProgramming.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

</Project>
17 changes: 17 additions & 0 deletions ConcurrentProgramming/Communication/QueueUsage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

//____________________________________________________________________________________________________________________________________
//
// Copyright (C) 2024, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community by pressing the `Watch` button and get started commenting using the discussion panel at
//
// https://github.com/mpostol/TP/discussions/182
//
//_____________________________________________________________________________________________________________________________________

namespace TP.ConcurrentProgramming.Communication
{
internal class QueueUsage
{
}
}
65 changes: 53 additions & 12 deletions ConcurrentProgramming/ConcurrentProgramming.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Threading", "Threading\Threading.csproj", "{048964DB-DD76-4E44-8944-819336DE6FFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThreadingUnitTest", "ThreadingUnitTest\ThreadingUnitTest.csproj", "{EEA36658-FEC8-44E1-BC27-5873A1E6F4E7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-Introduction", "01-Introduction", "{714FF0A4-62BB-4299-A636-A271FD362B9D}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
Expand All @@ -23,20 +19,34 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationModel", "Presen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationViewModelTest", "PresentationViewModelTest\PresentationViewModelTest.csproj", "{552FA4FE-BF99-4395-8BA5-CEDD87857DA5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-Fundamentals", "02-Fundamentals", "{9CD92A26-3971-4BB6-A246-02DD0BE3EDE5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03-CommonDataConsistency", "03-CommonDataConsistency", "{827AC87B-E6C6-422A-A8EA-A8A06835E7ED}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04-Synchronization", "04-Synchronization", "{6D532753-A18A-4AB7-8A6A-830F6668B744}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "05-Communication", "05-Communication", "{20429409-B6E9-4781-B409-A0A09A59BFB1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "06-Real-TimeProgramming", "06-Real-TimeProgramming", "{4DF351E7-784A-46BE-8583-C03C8A5AA9AA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fundamentals", "Fundamentals\Fundamentals.csproj", "{D656C8BE-A19F-4D90-85F5-3C23195B33AA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonDataConsistency", "CommonDataConsistency\CommonDataConsistency.csproj", "{1CCA366E-1D6A-4449-9346-53CE90F4EFE1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synchronization", "Synchronization\Synchronization.csproj", "{AE932064-1C42-42F3-AF7F-31103690C234}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Communication", "Communication\Communication.csproj", "{1B46B056-D61C-4D43-99E2-5A6F2942A382}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RealTimeProgramming", "RealTimeProgramming\RealTimeProgramming.csproj", "{B634E80A-9634-4D88-B4EC-E59DB5C46E0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FundamentalsTest", "FundamentalsTest\FundamentalsTest.csproj", "{5644D643-F468-4A8D-9201-0A82DEF881AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{048964DB-DD76-4E44-8944-819336DE6FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{048964DB-DD76-4E44-8944-819336DE6FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{048964DB-DD76-4E44-8944-819336DE6FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{048964DB-DD76-4E44-8944-819336DE6FFB}.Release|Any CPU.Build.0 = Release|Any CPU
{EEA36658-FEC8-44E1-BC27-5873A1E6F4E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEA36658-FEC8-44E1-BC27-5873A1E6F4E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEA36658-FEC8-44E1-BC27-5873A1E6F4E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEA36658-FEC8-44E1-BC27-5873A1E6F4E7}.Release|Any CPU.Build.0 = Release|Any CPU
{0109D5AC-DA81-4E6E-AA70-D4AF4B7A10D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0109D5AC-DA81-4E6E-AA70-D4AF4B7A10D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0109D5AC-DA81-4E6E-AA70-D4AF4B7A10D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -53,15 +63,46 @@ Global
{552FA4FE-BF99-4395-8BA5-CEDD87857DA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{552FA4FE-BF99-4395-8BA5-CEDD87857DA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{552FA4FE-BF99-4395-8BA5-CEDD87857DA5}.Release|Any CPU.Build.0 = Release|Any CPU
{D656C8BE-A19F-4D90-85F5-3C23195B33AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D656C8BE-A19F-4D90-85F5-3C23195B33AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D656C8BE-A19F-4D90-85F5-3C23195B33AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D656C8BE-A19F-4D90-85F5-3C23195B33AA}.Release|Any CPU.Build.0 = Release|Any CPU
{1CCA366E-1D6A-4449-9346-53CE90F4EFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CCA366E-1D6A-4449-9346-53CE90F4EFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CCA366E-1D6A-4449-9346-53CE90F4EFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CCA366E-1D6A-4449-9346-53CE90F4EFE1}.Release|Any CPU.Build.0 = Release|Any CPU
{AE932064-1C42-42F3-AF7F-31103690C234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE932064-1C42-42F3-AF7F-31103690C234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE932064-1C42-42F3-AF7F-31103690C234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE932064-1C42-42F3-AF7F-31103690C234}.Release|Any CPU.Build.0 = Release|Any CPU
{1B46B056-D61C-4D43-99E2-5A6F2942A382}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B46B056-D61C-4D43-99E2-5A6F2942A382}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B46B056-D61C-4D43-99E2-5A6F2942A382}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B46B056-D61C-4D43-99E2-5A6F2942A382}.Release|Any CPU.Build.0 = Release|Any CPU
{B634E80A-9634-4D88-B4EC-E59DB5C46E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B634E80A-9634-4D88-B4EC-E59DB5C46E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B634E80A-9634-4D88-B4EC-E59DB5C46E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B634E80A-9634-4D88-B4EC-E59DB5C46E0C}.Release|Any CPU.Build.0 = Release|Any CPU
{5644D643-F468-4A8D-9201-0A82DEF881AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5644D643-F468-4A8D-9201-0A82DEF881AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5644D643-F468-4A8D-9201-0A82DEF881AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5644D643-F468-4A8D-9201-0A82DEF881AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C3B041B9-20C2-4920-B0E5-CFE5784FC6E4} = {714FF0A4-62BB-4299-A636-A271FD362B9D}
{0109D5AC-DA81-4E6E-AA70-D4AF4B7A10D1} = {C3B041B9-20C2-4920-B0E5-CFE5784FC6E4}
{B2380645-D767-4E38-835A-3CA87C22CD20} = {C3B041B9-20C2-4920-B0E5-CFE5784FC6E4}
{A106D92E-B514-4FC0-BDE4-5DE1B8590060} = {C3B041B9-20C2-4920-B0E5-CFE5784FC6E4}
{552FA4FE-BF99-4395-8BA5-CEDD87857DA5} = {C3B041B9-20C2-4920-B0E5-CFE5784FC6E4}
{D656C8BE-A19F-4D90-85F5-3C23195B33AA} = {9CD92A26-3971-4BB6-A246-02DD0BE3EDE5}
{1CCA366E-1D6A-4449-9346-53CE90F4EFE1} = {827AC87B-E6C6-422A-A8EA-A8A06835E7ED}
{AE932064-1C42-42F3-AF7F-31103690C234} = {6D532753-A18A-4AB7-8A6A-830F6668B744}
{1B46B056-D61C-4D43-99E2-5A6F2942A382} = {20429409-B6E9-4781-B409-A0A09A59BFB1}
{B634E80A-9634-4D88-B4EC-E59DB5C46E0C} = {4DF351E7-784A-46BE-8583-C03C8A5AA9AA}
{5644D643-F468-4A8D-9201-0A82DEF881AB} = {9CD92A26-3971-4BB6-A246-02DD0BE3EDE5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4ACB1EF2-3819-4CE2-9F11-F8DBD7CDDFEC}
Expand Down
11 changes: 11 additions & 0 deletions ConcurrentProgramming/Fundamentals/Fundamentals.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>TP.ConcurrentProgramming.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>TP.ConcurrentProgramming.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions ConcurrentProgramming/Fundamentals/ThreadsCreations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//____________________________________________________________________________________________________________________________________
//
// Copyright (C) 2024, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community by pressing the `Watch` button and get started commenting using the discussion panel at
//
// https://github.com/mpostol/TP/discussions/182
//
//_____________________________________________________________________________________________________________________________________

namespace TP.ConcurrentProgramming.Fundamentals
{
public static class ThreadsCreations
{
public static Thread StartThread(ParameterizedThreadStart start)
{
Thread thread = new Thread(start);
thread.Start();
return thread;
}

public static void StartThreadsUsingThreadPool(WaitCallback start)
{
ThreadPool.QueueUserWorkItem(start);
}

public static Task StartThreadsUsingTask(Action start)
{
return Task.Run(start);
}
}
}
29 changes: 29 additions & 0 deletions ConcurrentProgramming/FundamentalsTest/FundamentalsTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<AssemblyName>TP.ConcurrentProgramming.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>TP.ConcurrentProgramming.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fundamentals\Fundamentals.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions ConcurrentProgramming/FundamentalsTest/ThreadsCreationsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//____________________________________________________________________________________________________________________________________
//
// Copyright (C) 2024, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community by pressing the `Watch` button and get started commenting using the discussion panel at
//
// https://github.com/mpostol/TP/discussions/182
//
//_____________________________________________________________________________________________________________________________________

using TP.ConcurrentProgramming.Fundamentals;

namespace TP.ConcurrentProgramming.FundamentalsTest
{
[TestClass]
public class ThreadsCreationsTest
{
[TestMethod]
public void StartThreadsTestMethod()
{
int counter = 0;
Thread[] _Threads = new Thread[2];
for (int i = 0; i < _Threads.Length; i++)
_Threads[i] = ThreadsCreations.StartThread(x => Interlocked.Add(ref counter, 1));
foreach (Thread _thread in _Threads)
_thread.Join();
}

[TestMethod]
public void tartThreadsUsingThreadPoolTestMethod()
{
int counter = 0;
for (int i = 0; i < 2; i++)
ThreadsCreations.StartThreadsUsingThreadPool(x => Interlocked.Add(ref counter, 1));
Thread.Sleep(100); //race condition possible
Assert.AreEqual<int>(2, counter);
}

[TestMethod]
public void StartThreadsUsingTaskTestMethod()
{
int counter = 0;
List<Task> _tasksInProgress = new List<Task>();
for (int i = 0; i < 2; i++)
_tasksInProgress.Add(ThreadsCreations.StartThreadsUsingTask(() => Interlocked.Add(ref counter, 1)));
Task.WaitAll(_tasksInProgress.ToArray());
Assert.AreEqual<int>(2, counter);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>TP.ConcurrentProgramming.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>TP.ConcurrentProgramming.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<VersionPrefix>4.2.0</VersionPrefix>
<Copyright>Copyright 2022 Mariusz Postol</Copyright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>

</Project>
Loading