❔ Cross Thread synchronization of locks
In over my head, I am trying to use a lock to pause some code on one thread, and i want to release (Monitor.Exit()) from another thread. How do i synchronise this?
71 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
im not aware of how to synchronise
because i am exiting from another thread that the lock was entered on, its throwing up an error
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
so this runs on a thread
the cw will be taken out, its just for testing purposes
then i call _halter.Exit(); from another Thread
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
queue
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
the idea of the locks was that it wasnt gonna infinitely run a while true loop
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
how does channel work?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
see
$channel
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Opinion: first article looks better as an introduction than the devblog one, but but should still be read in that order
https://ndportmann.com/system-threading-channels
https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels
https://www.stevejgordon.co.uk/an-introduction-to-system-threading-channels
Video:
https://docs.microsoft.com/en-us/shows/on-net/working-with-channels-in-net
Exploring System.Threading.Channels
A blog about software engineering and applied cryptography.
.NET Blog
An Introduction to System.Threading.Channels - .NET Blog
“Producer/consumer” problems are everywhere, in all facets of our lives. A line cook at a fast food restaurant, slicing tomatoes that are handed off to another cook to assemble a burger, which is handed off to a register worker to fulfill your order,
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i would probably agree. however
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
in a hypothetical situatuation where i needed to use a lock and queue
since this is for school xD
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
is it possible like how im trying?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i should probably read up a little on locks
not sure i understand this
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i have changed now trying to edit myself
heres original
it holds it until i exit it from the other thread
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
someone else mentioned reset events too, i had a look but im pressed on time for this
so looking for something simple as possible
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
no clue, its my coursework
its due friday. Teacher suddenly said he wants it done haha
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i need to finish the solution. Then complete testing and evaluation
for my school, the computer science course requires we complete a full project
Analysis, design, implementation, testing and evaluation
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
not sure, but i would be using months to measure not years
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i have played about with it for maybe 1.5 years, but for the first year i was playing with strings and arrays
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok
this is manual?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yes this one, so i use either or, or do i need both
AutoResetEvent Class (System.Threading)
Represents a thread synchronization event that, when signaled, resets automatically after releasing a single waiting thread. This class cannot be inherited.
i am reading here
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
so theres not a huge difference
a bit like having a using statement rather that calling .Close() ?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh, forget my question then haha
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
so i need manual i believe
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i may have 10+ threads all adding to queue
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok i see. I will look at channel again, hopefully i get my head around it pretty quick
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok sure, ill try plug it in and see what happens. But not gonna spend too long if it doesnt go well
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yes, will try this first
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i know a little about this
i used to use await Task.Run(() => SomeAsyncTask)
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i know haha
it was very bodge job code
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
but i said, i am still new and learning. This is my first proper project
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oke doke
appreciate your time
fingers crossed all goes well
So i was being dumb
i fixed using Locks and monitor
i just never synchronised the two threads by entering on both
only entered on one thread where i waited
from pule i need to enter then pulse then exit
i just pulsed
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
im aware, my bad
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Channel ftw
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.