If I access to the same memory adress at the same time it might have a "little" problem right?
So how do I solve it? (like checking if a specific adress is in use..)
Thanks.
Printable View
If I access to the same memory adress at the same time it might have a "little" problem right?
So how do I solve it? (like checking if a specific adress is in use..)
Thanks.
I don't know the C# specific way of doing this, but you can use something called a Semiphore or a Mutex. Well... nifty. I just did a quick google search for "c# semiphore" and this came up.
"Semaphore". The word has nothing to do with "semi".
Take a look at the lock statement
Beware of deadlocks though :)
First of all thanks (:
What is the first argument (Semaphore) meant to be for?
and if I don't want diffrent threads to use the same adress concurrently I need to set the second argument to 1?
and one more thing what is the diffrence between "lock statement" and "semaphore"?
Semaphore is a fancy name for a flag. Similar to a critical section. In this context you woudl test the state of the semaphore prior to entering the critical area and wait to procede until the flag is not set. Once enteing the critical area, you set the flag to rpevent other threads form modifying the protected resource, then you operate ont hat resource and when finished you reset the semaphore. Under windows, use CRITICAL_SECTION's. SEMAPHORE's under windows are generally reserved for interprocess locking, CRITICAL_SECTION's are for intraprocess locking.
When you say it, it seems to be very simple (and logical) but I don't see it that way \:
What is those counters meant to do?
and way they use array?
You may want to look at the Wiki for semaphore:
http://en.wikipedia.org/wiki/Semaphore_(programming)
--
Mats
This page doesn't exist yet.
oh thanks but the explanation is only connected with the "theory".
and why isn't it use only true or false?
What you are seeking is the pthread_mutex_lock function in C (or a lock { } block in C#), so only one thread can execute a particular piece of code at a time.