Search Results

Search found 418 results on 17 pages for 'race bannon'.

Page 1/17 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • What about race condition in multithreaded reading?

    - by themoob
    Hi, According to an article on IBM.com, "a race condition is a situation in which two or more threads or processes are reading or writing some shared data, and the final result depends on the timing of how the threads are scheduled. Race conditions can lead to unpredictable results and subtle program bugs." . Although the article concerns Java, I have in general been taught the same definition. As far as I know, simple operation of reading from RAM is composed of setting the states of specific input lines (address, read etc.) and reading the states of output lines. This is an operation that obviously cannot be executed simultaneously by two devices and has to be serialized. Now let's suppose we have a situation when a couple of threads access an object in memory. In theory, this access should be serialized in order to prevent race conditions. But e.g. the readers/writers algorithm assumes that an arbitrary number of readers can use the shared memory at the same time. So, the question is: does one have to implement an exclusive lock for read when using multithreading (in WinAPI e.g.)? If not, why? Where is this control implemented - OS, hardware? Best regards, Kuba

    Read the article

  • Elusive race condition in Java

    - by nasufara
    I am creating a graphing calculator. In an attempt to squeeze some more performance out of it, I added some multithreaded to the line calculator. Essentially what my current implementation does is construct a thread-safe Queue of X values, then start however many threads it needs, each one calculating a point on the line using the queue to get its values, and then ordering the points using a HashMap when the calculations are done. This implementation works great, and that's not where my race condition is (merely some background info). In examining the performance results from this, I found that the HashMap is a performance bottleneck, since I do that synchronously on one thread. So I figured that ordering each point as its calculated would work best. I tried a PriorityQueue, but that was slower than the HashMap. I ended up creating an algorithm that essentially works like this: I construct a list of X values to calculate, like in my current algorithm. I then copy that list of values into another class, unimaginatively and temporarily named BlockingList, which is responsible for ordering the points as they are calculated. BlockingList contains a put() method, which takes in two BigDecimals as parameters, the first the X value, the second the calculated Y value. put() will only accept a value if the X value is the next one on the list to be accepted in the list of X values, and will block until another thread gives it the next excepted value. For example, since that can be confusing, say I have two threads, Thread-1 and Thread-2. Thread-2 gets the X value 10.0 from the values queue, and Thread-1 gets 9.0. However, Thread-1 completes its calculations first, and calls put() before Thread-2 does. Because BlockingList is expecting to get 10.0 first, and not 9.0, it will block on Thread-1 until Thread-2 finishes and calls put(). Once Thread-2 gives BlockingList 10.0, it notify()s all waiting threads, and expects 9.0 next. This continues until BlockingList gets all of its expected values. (I apologise if that was hard to follow, if you need more clarification, just ask.) As expected by the question title, there is a race condition in here. If I run it without any System.out.printlns, it will sometimes lock because of conflicting wait() and notifyAll()s, but if I put a println in, it will run great. A small implementation of this is included below, and exhibits the same behavior: import java.math.BigDecimal; import java.util.concurrent.ConcurrentLinkedQueue; public class Example { public static void main(String[] args) throws InterruptedException { // Various scaling values, determined based on the graph size // in the real implementation BigDecimal xMax = new BigDecimal(10); BigDecimal xStep = new BigDecimal(0.05); // Construct the values list, from -10 to 10 final ConcurrentLinkedQueue<BigDecimal> values = new ConcurrentLinkedQueue<BigDecimal>(); for (BigDecimal i = new BigDecimal(-10); i.compareTo(xMax) <= 0; i = i.add(xStep)) { values.add(i); } // Contains the calculated values final BlockingList list = new BlockingList(values); for (int i = 0; i < 4; i++) { new Thread() { public void run() { BigDecimal x; // Keep looping until there are no more values while ((x = values.poll()) != null) { PointPair pair = new PointPair(); pair.realX = x; try { list.put(pair); } catch (Exception ex) { ex.printStackTrace(); } } } }.start(); } } private static class PointPair { public BigDecimal realX; } private static class BlockingList { private final ConcurrentLinkedQueue<BigDecimal> _values; private final ConcurrentLinkedQueue<PointPair> _list = new ConcurrentLinkedQueue<PointPair>(); public BlockingList(ConcurrentLinkedQueue<BigDecimal> expectedValues) throws InterruptedException { // Copy the values into a new queue BigDecimal[] arr = expectedValues.toArray(new BigDecimal[0]); _values = new ConcurrentLinkedQueue<BigDecimal>(); for (BigDecimal dec : arr) { _values.add(dec); } } public void put(PointPair item) throws InterruptedException { while (item.realX.compareTo(_values.peek()) != 0) { synchronized (this) { // Block until someone enters the next desired value wait(); } } _list.add(item); _values.poll(); synchronized (this) { notifyAll(); } } } } My question is can anybody help me find the threading error? Thanks!

    Read the article

  • SQL Server Process Queue Race Condition

    - by William Edmondson
    I have an order queue that is accessed by multiple order processors through a stored procedure. Each processor passes in a unique ID which is used to lock the next 20 orders for its own use. The stored procedure then returns these records to the order processor to be acted upon. There are cases where multiple processors are able to retrieve the same 'OrderTable' record at which point they try to simultaneously operate on it. This ultimately results in errors being thrown later in the process. My next course of action is to allow each processor grab all available orders and just round robin the processors but I was hoping to simply make this section of code thread safe and allow the processors to grab records whenever they like. So Explicitly - Any idea why I am experiencing this race condition and how I can solve the problem. BEGIN TRAN UPDATE OrderTable WITH ( ROWLOCK ) SET ProcessorID = @PROCID WHERE OrderID IN ( SELECT TOP ( 20 ) OrderID FROM OrderTable WITH ( ROWLOCK ) WHERE ProcessorID = 0) COMMIT TRAN SELECT OrderID, ProcessorID, etc... FROM OrderTable WHERE ProcessorID = @PROCID

    Read the article

  • prevent race condition without using locks C++

    - by Hristo
    How do I prevent a race condition with locking or using mutexes/semaphors in C++? I'm dealing with a nested for loop in which I will be setting a value in an array: for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < o; ++k) array[k] += foo(...); More or less, I want to deal with this so that I can ensure different threads running at the same time don't write to array[k] at the same time. Any suggestions on how to approach this? Thanks, Hristo

    Read the article

  • Race condition for thread startup

    - by Ozzah
    A similar question was asked here, but the answers generally all seem to relate to the lambda notation. I get a similar result without the lambda so I thought I'd ask for some clarification: Say I have something like this: for (int i = 0; i < 5; i++) (new Thread(new ThreadStart(delegate() { Console.WriteLine("Thread " + i); }))).Start(); One would expect the following output: Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Now I realise that the threads aren't started in any particular order, so let's just assume that the above lines can come out in any order. But that is not what happens. What instead happens: Thread 3 Thread 4 Thread 4 Thread 4 Thread 4 or something similar, which leads me to believe that rather than passing the value if i, it is passing the reference. (Which is weird, since an int is a value type). Doing something like this: for (int i = 0; i < 5; i++) (new Thread(new ThreadStart(delegate() { int j = i; Console.WriteLine("Thread " + j); }))).Start(); does not help either, even though we have made a copy of i. I am assuming the reason is that it hasn't made a copy of i in time. Doing something like this: for (int i = 0; i < 5; i++) { (new Thread(new ThreadStart(delegate() { Console.WriteLine("Thread " + i); }))).Start(); Thread.Sleep(50); } seems to fix the problem, however it is extremely undesirable as we're wasting 50ms on each iteration, not to mention the fact that if the computer is heavily loaded then maybe 50ms may not be enough. Here is a sample with my current, specific problem: Thread t = new Thread(new ThreadStart(delgate() { threadLogic(param1, param2, param3, param4); })); t.Start(); param1 = param2 = param3 = param4 = null; with: void threadLogic(object param1, object param2, object param3, object param4) { // Do some stuff here... } I want threadLogic() to run in its own thread, however the above code gives a null reference exception. I assume this is because the values are set to null before the thread has had a chance to start. Again, putting a Thread.Sleep(100) works, but it is an awful solution from every aspect. What do you guys recommend for this particular type of race condition?

    Read the article

  • Dropbox’s Great Space Race Delivers Additional Space to Students

    - by Jason Fitzpatrick
    If you’re a student or faculty member (or still have an active .edu email account) now’s the time to cash in on some free cloud storage courtesy of Dropbox’s Great Space Race. Just by linking your .edu address with your Dropbox account you’ll get an extra 3GB of storage for the next two years. The more people from your school that sign up, the higher the total climbs–up to an extra 25GB for two years. The Space Race lasts for the next eight weeks, you can read more about the details here or just jump to the signup page at the link below. The Great Space Race [Dropbox] Why Enabling “Do Not Track” Doesn’t Stop You From Being Tracked HTG Explains: What is the Windows Page File and Should You Disable It? How To Get a Better Wireless Signal and Reduce Wireless Network Interference

    Read the article

  • Race condition firing events in AS3

    - by crispclean
    Hello I have some troubles firing and removing events in the right chronicle order. The code below gives the following output: save poster into db, and dispatch event calling service, dispatch event removed = false calling service, dispatch event removed = false calling service, dispatch event removed = true save poster into db, and dispatch event save poster into db, and dispatch event of course this should be more something like: save poster into db, and dispatch event calling service, dispatch event removed = true save poster into db, and dispatch event calling service, dispatch event removed = true save poster into db, and dispatch event calling service, dispatch event removed = true Can someone help me with this? I'm running out of ideas on how to tackle this. thx! for(var i:int = 0;i< 3;i++){ createPoster(); } function createPoster(){ Main.db.savePoster(); Main.db.addEventListener(Config.evt_SAVEPOSTER_READY, callService); } function callService(){ Main.db.removeEventListener(Config.evt_SAVEPOSTER_READY, callService); }

    Read the article

  • Long running method causing race condition

    - by keeleyt83
    Hi, I'm relatively new with hibernate so please be gentle. I'm having an issue with a long running method (~2 min long) and changing the value of a status field on an object stored in the DB. The pseudo-code below should help explain my issue. public foo(thing) { if (thing.getStatus() == "ready") { thing.setStatus("finished"); doSomethingAndTakeALongTime(); } else { // Thing already has a status of finished. Send the user back a message. } } The pseudo-code shouldn't take much explanation. I want doSomethingAndTakeALongTime() to run, but only if it has a status of "ready". My issue arises whenever it takes 2 minutes for doSomethingAndTakeALongTime() to finish and the change to thing's status field doesn't get persisted to the database until it leaves foo(). So another user can put in a request during those 2 minutes and the if statement will evaluate to true. I've already tried updating the field and flushing the session manually, but it didn't seem to work. I'm not sure what to do from here and would appreciate any help. PS: My hibernate session is managed by spring.

    Read the article

  • Preventing Race Conditions

    - by Qua
    I'm using the built-in ajax functionality of MVC2. Basically the user types a search query, and on every key press a set of results for the query is shown. This works fine in almost all cases, but sometimes the server is a bit slow with a single response, and thus the result for the next key stroke is returned before the previous. When the previous key stroke result set is finally returned to the client it will overwrite the results for the newer search query that should actually have been shown. My code follows more or less along these lines: <% using (Ajax.BeginForm("SearchUser", null, new AjaxOptions() { UpdateTargetId = "findUserResults" }, new { id = "findUserAjaxForm" })) {%> Every keystroke submits this form and thus outputs the results in the 'findUserResults' element. How can I prevent older results from being displayed while still making use of the built-in functions provided in MVC2?

    Read the article

  • Editing files without race conditions?

    - by user2569445
    I have a CSV file that needs to be edited by multiple processes at the same time. My question is, how can I do this without introducing race conditions? It's easy to write to the end of the file without race conditions by open(2)ing it in "a" (O_APPEND) mode and simply write to it. Things get more difficult when removing lines from the file. The easiest solution is to read the file into memory, make changes to it, and overwrite it back to the file. If another process writes to it after it is in memory, however, that new data will be lost upon overwriting. To further complicate matters, my platform does not support POSIX record locks, checking for file existence is a race condition waiting to happen, rename(2) replaces the destination file if it exists instead of failing, and editing files in-place leaves empty bytes in it unless the remaining bytes are shifted towards the beginning of the file. My idea for removing a line is this (in pseudocode): filename = "/home/user/somefile"; file = open(filename, "r"); tmp = open(filename+".tmp", "ax") || die("could not create tmp file"); //"a" is O_APPEND, "x" is O_EXCL|O_CREAT while(write(tmp, read(file)); //copy the $file to $file+".new" close(file); //edit tmp file unlink(filename) || die("could not unlink file"); file = open(filename, "wx") || die("another process must have written to the file after we copied it."); //"w" is overwrite, "x" is force file creation while(write(file, read(tmp))); //copy ".tmp" back to the original file unlink(filename+".tmp") || die("could not unlink tmp file"); Or would I be better off with a simple lock file? Appender process: lock = open(filename+".lock", "wx") || die("could not lock file"); file = open(filename, "a"); write(file, "stuff"); close(file); close(lock); unlink(filename+".lock"); Editor process: lock = open(filename+".lock", "wx") || die("could not lock file"); file = open(filename, "rw"); while(contents += read(file)); //edit "contents" write(file, contents); close(file); close(lock); unlink(filename+".lock"); Both of these rely on an additional file that will be left over if a process terminates before unlinking it, causing other processes to refuse to write to the original file. In my opinion, these problems are brought on by the fact that the OS allows multiple writable file descriptors to be opened on the same file at the same time, instead of failing if a writable file descriptor is already open. It seems that O_CREAT|O_EXCL is the closest thing to a real solution for preventing filesystem race conditions, aside from POSIX record locks. Another possible solution is to separate the file into multiple files and directories, so that more granular control can be gained over components (lines, fields) of the file using O_CREAT|O_EXCL. For example, "file/$id/$field" would contain the value of column $field of the line $id. It wouldn't be a CSV file anymore, but it might just work. Yes, I know I should be using a database for this as databases are built to handle these types of problems, but the program is relatively simple and I was hoping to avoid the overhead. So, would any of these patterns work? Is there a better way? Any insight into these kinds of problems would be appreciated.

    Read the article

  • Classic Video Game Characters Race Against Each Other Parts 1 & 2 [Videos]

    - by Asian Angel
    Have you ever wondered who might win if all of your favorite video game characters were pitted against each other in a race? Then sit back and enjoy not one, but two races to the finish with this awesome pair of videos! Why Does 64-Bit Windows Need a Separate “Program Files (x86)” Folder? Why Your Android Phone Isn’t Getting Operating System Updates and What You Can Do About It How To Delete, Move, or Rename Locked Files in Windows

    Read the article

  • CVE-2013-0900 Race Conditions vulnerability in ICU

    - by Ritwik Ghoshal
    CVE DescriptionCVSSv2 Base ScoreComponentProduct and Resolution CVE-2013-0900 Race Conditions vulnerability 6.8 International Components for Unicode (ICU) Solaris 10 SPARC: 119810-08 X86: 119811-08 Solaris 11.1 11.1.16.5.0 This notification describes vulnerabilities fixed in third-party components that are included in Oracle's product distributions.Information about vulnerabilities affecting Oracle products can be found on Oracle Critical Patch Updates and Security Alerts page.

    Read the article

  • migrating product and team from startup race to quality development

    - by thevikas
    This is year 3 and product is selling good enough. Now we need to enforce good software development practices. The goal is to monitor incoming bug reports and reduce them, allow never ending features and get ready for scaling 10x. The phrases "test-driven-development" and "continuous-integration" are not even understood by the team cause they were all in the first 2 year product race. Tech team size is 5. The question is how to sell/convince team and management about TDD/unit testing/coding standards/documentation - with economics. train the team to do more than just feature coding and start writing test units along - which looks like more work, means needs more time! how to plan for creating units for all backlog production code

    Read the article

  • MSDN Example of handling an exception from the TPL - Is this a race condition?

    - by David
    I'm looking at the TPL exception handling example from MSDN @ http://msdn.microsoft.com/en-us/library/dd537614(v=VS.100).aspx The basic form of the code is: Task task1 = Task.Factory.StartNew(() => { throw new IndexOutOfRangeException(); }); try { task1.Wait(); } catch (AggregateException ae) { throw ae.Flatten(); } My question is: Is this a race condition? What happens if task1 throws before the try has executed? Am I missing something that stops this being a race? Shouldn't it be written like this instead: try { Task task1 = Task.Factory.StartNew(() => { throw new IndexOutOfRangeException(); }); task1.Wait(); } catch (AggregateException ae) { throw ae.Flatten(); }

    Read the article

  • java methods and race condition in a jsp/servlets application.

    - by A.S al-shammari
    Hi. Suppose that I have a method called doSomething() and I want to use this method in a multithreaded application (each servlet inherits from HttpServlet).I'm wondering if it is possible that a race condition will occur in the following cases: doSomething() is not staic method and it writes values to a database. doSomething() is static method but it does not write values to a database. what I have noticed that many methods in my application may lead to a race condition or dirty read/write. for example , I have a Poll System , and for each voting operation, a certain method will change a single cell value for that poll as the following: [poll_id | poll_data ] [1 | {choice_1 : 10, choice_2 : 20}] will the JSP/Servlets app solve these issues by itself, or I have to solve all that by myself? Thanks..

    Read the article

  • Does a transaction stop all race condition problems in MySQL?

    - by nickf
    Consider this situation: Begin transaction Insert 20 records into a table with an auto_increment key Get the first insert id (let's say it's 153) Update all records in that table where id >= 153 Commit Is step 4 safe? That is, if another request comes in almost precisely at the same time, and inserts another 20 records after step 2 above, but before step 4, will there be a race condition?

    Read the article

  • Does a static object within a function introduce a potential race condition?

    - by Jeremy Friesner
    I'm curious about the following code: class MyClass { public: MyClass() : _myArray(new int[1024]) {} ~MyClass() {delete [] _myArray;} private: int * _myArray; }; // This function may be called by different threads in an unsynchronized manner void MyFunction() { static const MyClass _myClassObject; [...] } Is there a possible race condition in the above code? Specifically, is the compiler likely to generate code equivalent to the following, "behind the scenes"? void MyFunction() { static bool _myClassObjectInitialized = false; if (_myClassObjectInitialized == false) { _myClassObjectInitialized = true; _myClassObject.MyClass(); // call constructor to set up object } [...] } ... in which case, if two threads were to call MyFunction() nearly-simultaneously, then _myArray might get allocated twice, causing a memory leak? Or is this handled correctly somehow?

    Read the article

  • How do I prevent race condition WITHOUT using locks in C++?

    - by Hristo
    How do I prevent a race condition WITHOUT locking or using mutexes/semaphors in C++? I'm dealing with a nested for loop in which I will be setting a value in an array: for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < o; ++k) array[k] += foo(...); More or less, I want to deal with this so that I can ensure different threads running at the same time don't write to array[k] at the same time. Any suggestions on how to approach this? Edit: I am running on a Linux machine and I also have to use the Intel compiler. I will be using "icc" instead of "gcc" to compile the code.

    Read the article

  • How do I make this Java code operate properly? [Multi-threaded, race condition]

    - by Fixee
    I got this code from a student, and it does not work properly because of a race condition involving x++ and x--. He added synchronized to the run() method trying to get rid of this bug, but obviously this only excludes threads from entering run() on the same object (which was never a problem in the first place) but doesn't prevent independent objects from updating the same static variable x at the same time. public class DataRace implements Runnable { static volatile int x; public synchronized void run() { for (int i = 0; i < 10000; i++) { x++; x--; } } public static void main(String[] args) throws Exception { Thread [] threads = new Thread[100]; for (int i = 0; i < threads.length; i++) threads[i] = new Thread(new DataRace()); for (int i = 0; i < threads.length; i++) threads[i].start(); for (int i = 0; i < threads.length; i++) threads[i].join(); System.out.println(x); // x not always 0! } } Since we cannot synchronize on x (because it is primitive), the best solution I can think of is to create a new static object like static String lock = ""; and enclose the x++ and x-- within a synchronized block, locking on lock. But this seems really awkward. Is there a better way?

    Read the article

  • Marionette js itemview not defined: then on browser refresh it is defined and all works well - race condition?

    - by Robert
    Yeah it's just the initial browser load or two after a cache clear. Subsequent refreshes clear the problem up. I'm thinking the item views just aren't fully constructed in time to be used in the collection views on the first load. But then they are on a refresh? Don't know. There must be something about the code sequence or loading or the load time itself. Not sure. I'm loading via require.js. Have two collections - users and messages. Each renders in its own list view. Each works, just not the first time or two the browser loads. The first time you load after clearing browser cache the console reports, for instance: "Uncaught ReferenceError: MessageItemView is not defined" A simple browser refresh clears it up. Same goes for the user collection. It's collection view says it doesn't know anything about its item view. But a simple browser refresh and all is well. My views (item and collection) are in separate files. Is that the problem? For instance, here is my message collection view in its own file: messagelistview.js var MessageListView = Marionette.CollectionView.extend({ itemView: MessageItemView, el: $("#messages") }); And the message item view is in a separate file: messageview.js var MessageItemView = Marionette.ItemView.extend({ tagName: "div", template: Handlebars.compile( '<div>{{fromUserName}}:</div>' + '<div>{{message}}</div>' + ) }); Then in my main module file, which references each of those files, the collection view is constructed and displayed: main.js //Define a model MessageModel = Backbone.Model.extend(); //Make an instance of MessageItemView - code in separate file, messagelistview.js MessageView = new MessageItemView(); //Define a message collection var MessageCollection = Backbone.Collection.extend({ model: MessageModel }); //Make an instance of MessageCollection var collMessages = new MessageCollection(); //Make an instance of a MessageListView - code in separate file, messagelistview.js var messageListView = new MessageListView({ collection: collMessages }); App.messageListRegion.show(messageListView); Do I just have things sequenced wrong? I'm thinking it's some kind of race condition only because over 3G to an iPad the item views are always undefined. They never seem to get constructed in time. PC on a hard wired connection does see success after a browser refresh or two.

    Read the article

  • nginx connection pool race condition?

    - by wlf
    I have a shared hosting server with high traffic. I have a lightweight apache mod_proxy for static content that from time to time has a "504 proxy error" problem proxing to apache/mod_php. Error log says: error reading status line from remote server 127.0.0.1:8080 Error reading from remote server returned by / This is what the apache documentation says about it. proxy-initial-not-pooled If this variable is set no pooled connection will be reused if the client connection is an initial connection. This avoids the "proxy: error reading status line from remote server" error message caused by the race condition that the backend server closed the pooled connection after the connection check by the proxy and before data sent by the proxy reached the backend. It has to be kept in mind that setting this variable downgrades performance, especially with HTTP/1.0 clients. I am really concerned about this downgrade in performance therefore I started to look at nginx immediately. I am new to nginx and time is crucial right now, I can't afford to waste days to study it just to find out there is the same race condition issue. Is nginx affected by this connection pool race condition? Thanks

    Read the article

  • Implementation of Race Game Tree

    - by Mert Toka
    I build a racing game right in OpenGL using Glut, and I'm a bit lost in all the details. First of all, any suggestions as a road map would be more than great. So far what I thought is this: Tree implementation for transformations. Simulated dynamics.(*) Octree implementation for collusion detection. Actual collusion detection.(*) Modelling in Maya and export them as .OBJs. Polishing the game with GLSL or something like that for graphics quality. (*): I am not sure the order of these two. So I started with the simulated dynamics without tree, and it turned out to be a huge chaos for me. Is there any way you can think of such that could help me to build such tree to use in racing game? I thought something like this but I have no idea how to implement it. Reds are static, yellows are dynamic nodes

    Read the article

  • Car Modelling for race game

    - by Mert Toka
    I am taking Computer Graphics course this semester and we have a video game competition. I am making racing game with simulated dynamics. Our professor told us that we don't have to do much of a modelling but since we haven't started the gaming part and since I have free time I want to model the car. My question is firstly which software do you recommend to design game components? I know Maya right now. Secondly, if I design the car or any other part, what should its polygon count in order to run game smoothly? I can design pretty much everything but I assume that it is hard to design low-poly models.

    Read the article

  • Does this use of Monitor.Wait/Pulse have a race condition?

    - by jw
    I have a simple producer/consumer scenario, where there is only ever a single item being produced/consumed. Also, the producer waits for the worker thread to finish before continuing. I realize that kind of obviates the whole point of multithreading, but please just assume it really needs to be this way (: This code doesn't compile, but I hope you get the idea: // m_data is initially null // This could be called by any number of producer threads simultaneously void SetData(object foo) { lock(x) // Line A { assert(m_data == null); m_data = foo; Monitor.Pulse(x) // Line B while(m_data != null) Monitor.Wait(x) // Line C } } // This is only ever called by a single worker thread void UseData() { lock(x) // Line D { while(m_data == null) Monitor.Wait(x) // Line E // here, do something with m_data m_data = null; Monitor.Pulse(x) // Line F } } Here is the situation that I am not sure about: Suppose many threads call SetData() with different inputs. Only one of them will get inside the lock, and the rest will be blocked on Line A. Suppose the one that got inside the lock sets m_data and makes its way to Line C. Question: Could the Wait() on Line C allow another thread at Line A to obtain the lock and overwrite m_data before the worker thread even gets to it? Supposing that doesn't happen, and the worker thread processes the original m_data, and eventually makes its way to Line F, what happens when that Pulse() goes off? Will only the thread waiting on Line C be able to get the lock? Or will it be competing with all the other threads waiting on Line A as well? Essentially, I want to know if Pulse()/Wait() communicate with each other specially "under the hood" or if they are on the same level with lock(). The solution to these problems, if they exist, is obvious of course - just surround SetData() with another lock - say, lock(y). I'm just curious if it's even an issue to begin with.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >