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.
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.
gavra.
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".
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Take a look at the lock statement
Beware of deadlocks though
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
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"?
Last edited by gavra; 09-17-2008 at 08:12 AM.
gavra.
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?
gavra.
You may want to look at the Wiki for semaphore:
http://en.wikipedia.org/wiki/Semaphore_(programming)
--
Mats
Last edited by matsp; 09-17-2008 at 09:39 AM. Reason: Edit Fix the URL.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
oh thanks but the explanation is only connected with the "theory".
and why isn't it use only true or false?
gavra.
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.