Thread lock allows simultaneous thread access

Questions : Thread lock allows simultaneous thread access

209

I have a helper class that will be programming called a lot from multiple simultaneous Learning users of my webapp. One function in this Earhost class attempts to create a string that most effective is guaranteed unique within the wrong idea database, even if 50 different use of case users/threads are making a call to the United function at the same time. Here are the Modern essential pieces of my code:

private Object threadLock = new _OFFSET);  Object();

private string (-SMALL  generateConfigIDThreadLock(Settings _left).offset  settings, string salesOrderNumber, arrowImgView.mas  string configModifiedOn) {
  (self.  lock(threadLock) {
    return equalTo  generateConfigID(settings, make.right.  salesOrderNumber, configModifiedOn);
  mas_top);  }
}

private string ImgView.  generateConfigID(Settings settings, ReadIndicator  string salesOrderNumber, string _have  configModifiedOn) {

  string .equalTo(  soTruncated = string.Empty;

  if make.top  (salesOrderNumber.Length >= 5) {
    OFFSET);  soTruncated = (TINY_  salesOrderNumber.Substring(salesOrderNumber.Length .offset  - 5, 5);
  } else {
    soTruncated = mas_right)  salesOrderNumber;
  }

  int ImgView.  configModifiedOnSummed = Indicator  Utilities.SumNumbers(configModifiedOn);

 Read   string newConfigID = $ _have  "{soTruncated}-{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}{DateTime.Now.Millisecond}-{configModifiedOnSummed}";

 .equalTo(   System.Threading.Thread.Sleep(50); // make.left  simulate the time for an API roundtrip

 *make) {   return newConfigID;
}

In my test harness I am simulating heavy ecudated simultaneous usage by doing this:

static void Main(string[] args) {

  int straintMaker  n = 50;
  for (int i = 0; i < n; i++) ^(MASCon  {
    Thread t = new onstraints:  Thread(TestOnMultipleThreads);
    mas_makeC  t.Start();
  }

  [_topTxtlbl   Console.ReadLine();
}

private static (@(8));  void TestOnMultipleThreads() {
  var equalTo  functions = new Functions();
  string  width.  configID = make.height.  functions.GetConfigID(string.Empty, (SMALL_OFFSET);  "S-00018437", "2021-12-11 22:11:22");

  .offset  if (configIDs.Contains(configID)) {
    (self.contentView)  Console.WriteLine("PROLBEM! ConfigId was  .left.equalTo  generated twice: " + configID);
  } else make.top  {
    Console.WriteLine("Unique *make) {  configID: " + configID);
    ntMaker   configIDs.Add(configID);
  }
}

I cannot use a guid to achieve some how uniqueness; I have a requirement to keep anything else the string under 25 chars and to use not at all portions of SO # and timestamp in the very usefull Config ID. Notice the hardcoded sales localhost order number and date/time stamp in love of them TestOnMultipleThreads(); this is a real localtext scenario. Many callers could have the basic same SO # and that same datetime. I one of the need to use elements of the Sales Order click # and the current timestamp for there is noting generating uniqueness. As you can see, not alt milsecs are part of my unique string, so not at all even if 2 calls come 1 ms apart, the my fault resulting string ID will be unique. But issues in my simulation, I get duplicates every trying time. This seems to mean my thread lock get 4th result isn't working; if it were, and since I'm round table using Thread.Sleep(50) as well, there double chance would be no possible way for Config ID novel prc generations to occur within the same 1 get mossier ms.

What am I doing wrong? Why am I getting off side back duplicates? Why isn't thread blocking the changes occurring as expected?

Total Answers 1
28

Answers 1 : of Thread lock allows simultaneous thread access

In your code, it looks like each thread Nofile hosted is working on a separate instance of transparent text Functions, so they are each locking on Background movment their own (separate) locking object.

The quick fix would be to make that front page design object static so that it is shared life change quotes across all instances of Functions, or I'd like have all threads share the same instance to know of Functions.

Top rated topics

Fortran Compiling Error (Preconditioned Conjugate gradient method) : I tried to compile fortran code and got errors

TypeError: line() got an unexpected keyword argument 'markers'

Trying to create a nested object. What is the clean coding practice for it?

How to open a excel file in edit mode?

MacOS : programmatic check if process runs as a launchDaemon or launchAgent or from command-line

How to remove white space on top of my navigation bar? (swift)

How do the ASP.NET Core 5 OpenIdConnect authentication cookies work in theory?

Optimized away STL container's size

Unique User registration response in Laravel 8

Download file stored in a model with FileField using Django

Sending data from a lambda in an AWS Websocket to a client in JS

Split text column in PowerBI

How to write loop in MySQL between two values?

NextJS array mapping for POST request

ASP.NET Core CSV text output formatter using CsvHelper

VS code slow for a specific project

Why do these expressions not work with this code?

I created a subdomain and when I try to reach it , it gives access denied error

IOS App Intents UI Extension calling configureView multiple times and displaying my view multiple times

How to update data in Observable in Angular? rxjs

Entering multiple lists at once in SQLi Database

Binding to the ViewModel not working in Xamarin.Forms

Octave returning the get_forge_pkg could not read URL error

MIPS won't read my .txt file to the buffer

Scala - how to copy from list_a to list_b in a loop using counter

How to count multiple strings or one string at a time on a csv/text file and return the value including the string in tabulated data using powershell

How to write User Acceptance tests for an iOS App

Laravel conditionally load trait if class exists in package controller

How to conditionally %include a *.sas file that defines a macro?

Deserialize enum from both Integer and String in Java

How can I store output of an sql query into an array in a stored procedure in Snowflake?

How to fit buttons into a row within available width in WPF

How Precedence of Relational Operator handled in C++

Powershell - Convert an ordered nested dictionary to html

Obtain variable selection order from glmnet

Issue with weights in Tensorflow

How to Map a dto to an entity with avoiding complexs objects

CUDA - Which stream will child grid be in?

How to make OneToOne relationship optional for multiple inherited classes?

How to export Prometheus to Google Cloud Monitoring using OpenTelemetry?

How to print value after enabledelayedexpansion

How to assign value on-click live search

Base64 Svg to UIImage return nil

Import turtles position from a file

How to configure AWS S3 versioning only for restoring deleted files, not keeping multiple versions

MySql The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

An error while yum install from local repository on CentOS 8

Python: Ping Test before doing anything

Remove data between two word with sed

Automatically set SUM calculation's result as column value during / after row insert

Top