Question How to handle multithread on singleton pattern ?

ahmedsa

Member
Joined
Jan 22, 2014
Messages
6
Programming Experience
1-3
I work on web api with asp.net core 3.1 I use singelton pattern on my web app

so my question is

on singlton pattern objects are the same for every object and every request so

How to handle multithread on singleton pattern ?
 
Inside each public method, getter/setter, and event raise method of your singleton object you would wrap the code with a critical section (aka lock). Critical sections will lock out other threads but allow the same thread to continue to use the singleton. Other threads trying to access the object will wait until the critical section is released.

 
Back
Top Bottom