Search Results

Search found 2601 results on 105 pages for 'if condition'.

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

  • LINQ - if condition

    - by ile
    In code, the commented part is what I need to solve... Is there a way to write such query in LINQ? I need this because I will need sorting based on Status. var result = ( from contact in db.Contacts join user in db.Users on contact.CreatedByUserID equals user.UserID join deal in db.Deals on contact.ContactID equals deal.ContactID into deals orderby contact.ContactID descending select new ContactListView { ContactID = contact.ContactID, FirstName = contact.FirstName, LastName = contact.LastName, Email = contact.Email, Deals = deals.Count(), EstValue = deals.Sum(e => e.EstValue), SalesAgent = user.FirstName + " " + user.LastName, Tasks = 7, // This is critical part if(Deals == 0) Status = "Prospect"; else Status = "Client"; // End of critical part... }) .OrderBy(filterQuery.OrderBy + " " + filterQuery.OrderType) .Where(filterQuery.Status);

    Read the article

  • MySQL select one field from table WHERE condition is in multiple rows

    - by Alex
    Tried to find the answer, but still couldn't.. The table is as follows: id, keyword, value 1 display 15.6 1 harddrive 320 1 ram 3 So what i need is something like this.. Select an id from this table where (keyword="display" and value="15.6") AND (keyword="harddrive" and value="320") There's also a possibility that there will be 3 or 4 such keyword conditions which should result into returning one id (one row) It seems there's something to deal with UNION but i didn't use it before so i can't figure it out Thanks in advance

    Read the article

  • how to change the while loop condition depending on stuff?

    - by linkcool
    by this question what i mean is that if, by example, someone's username is "bob" then the while loop condition will be ($i < 10), and if the username is something else then the while loop condition will be ($i 10) if($username == "bob") { //make this while loop condition: ($i < 10) // it means: while($i <10){ so stuff} } else { //make the while loop condition: ($i >10) }

    Read the article

  • how ot change the while loop condition depending on stuff?

    - by linkcool
    by this question what i mean is that if, by example, someone's username is "bob" then the while loop condition will be ($i < 10), and if the username is something else then the while loop condition will be ($i 10) if($username == "bob") { //make this while loop condition: ($i < 10) // it means: while($i <10){ so stuff} } else { //make the while loop condition: ($i >10) }

    Read the article

  • How can I improve my real-time behavior in multi-threaded app using pthreads and condition variables

    - by WilliamKF
    I have a multi-threaded application that is using pthreads. I have a mutex() lock and condition variables(). There are two threads, one thread is producing data for the second thread, a worker, which is trying to process the produced data in a real time fashion such that one chuck is processed as close to the elapsing of a fixed time period as possible. This works pretty well, however, occasionally when the producer thread releases the condition upon which the worker is waiting, a delay of up to almost a whole second is seen before the worker thread gets control and executes again. I know this because right before the producer releases the condition upon which the worker is waiting, it does a chuck of processing for the worker if it is time to process another chuck, then immediately upon receiving the condition in the worker thread, it also does a chuck of processing if it is time to process another chuck. In this later case, I am seeing that I am late processing the chuck many times. I'd like to eliminate this lost efficiency and do what I can to keep the chucks ticking away as close to possible to the desired frequency. Is there anything I can do to reduce the delay between the release condition from the producer and the detection that that condition is released such that the worker resumes processing? For example, would it help for the producer to call something to force itself to be context switched out? Bottom line is the worker has to wait each time it asks the producer to create work for itself so that the producer can muck with the worker's data structures before telling the worker it is ready to run in parallel again. This period of exclusive access by the producer is meant to be short, but during this period, I am also checking for real-time work to be done by the producer on behalf of the worker while the producer has exclusive access. Somehow my hand off back to running in parallel again results in significant delay occasionally that I would like to avoid. Please suggest how this might be best accomplished.

    Read the article

  • What does Visual studio debugger do, when condition should give error

    - by zacharmarz
    I'm debugging some code and I need to break everytime, when character in string (const char *) is equal to something. So I put there breakpoint and attach condition like: s[0] == 'e'. But code I'm debugging is in CRT and there is possibility, that s == 0 is true. So "addressing empty pointer" should give some kind of error. Yes - I could give there condition s != 0, but it would not be such fun :) And I'm curious, what will debugger do when trying to evaluate this condition? How it will behave internally? Obviously it's not giving any error nor stopping on this breakpoint when s == 0 Thanks for your answer.

    Read the article

  • OEG11gR2 integration with OES11gR2 Authorization with condition

    - by pgoutin
    Introduction This OES use-case has been defined originally by Subbu Devulapalli (http://accessmanagement.wordpress.com/).  Based on this OES museum use-case, I have developed the OEG11gR2 policy able to deal with the OES authorization with condition. From an OEG point of view, the way to deal with OES condition is to provide with the OES request some Environmental / Context Attributes.   Museum Use-Case  All painting in the museum have security sensors, an alarm goes off when a person comes too close a painting. The employee designated for maintenance needs to use their ID and disable the alarm before maintenance. You are the Security Administrator for the museum and you have been tasked with creating authorization policies to manage authorization for different paintings. Your first task is to understand how paintings are organized. Asking around, you are surprised to see that there isno formal process in place, so you need to start from scratch. the museum tracks the following attributes for each painting 1. Name of the work 2. Painter 3. Condition (good/poor) 4. Cost You compile the list of paintings  Name of Painting  Painter  Paint Condition  Cost  Mona Lisa  Leonardo da Vinci  Good  100  Magi  Leonardo da Vinci  Poor  40  Starry Night  Vincent Van Gogh  Poor  75  Still Life  Vincent Van Gogh  Good  25 Being a software geek who doesn’t (yet) understand art, you feel that price(or insurance price) of a painting is the most important criteria. So you feel that based on years-of-experience employees can be tasked with maintaining different paintings. You decide that paintings worth over 50 cost should be only handled by employees with over 20 years of experience and employees with less than 10 years of experience should not handle any painting. Lets us start with policy modeling. All paintings have a common set of attributes and actions, so it will be good to have them under a single Resource Type. Based on this resource type we will create the actual resources. So our high level model is: 1) Resource Type: Painting which has action manage and the following four attributes a) Name of the work b) Painter c) Condition (good/poor) d) Cost 2) To keep things simple lets use painting name for Resource name (in real world you will try to use some identifier which is unique, because in future we may end up with more than one painting which has the same name.) 3) Create Resources based on the previous table 4) Create an identity attribute Experience (Integer) 5) Create the following authorization policies a) Allow employees with over 20 years experience to access all paintings b) Allow employees with 10 – 20 years of experience to access painting which cost less than 50 c) Deny access to all paintings for employees with less than 10 year of experience OES Authorization Configuration We do need to create 2 authorization policies with specific conditions a) Allow employees with over 20 years experience to access all paintings b) Allow employees with 10 – 20 years of experience to access painting which cost less than 50 c) Deny access to all paintings for employees with less than 10 year of experience We don’t need an explicit policy for Deny access to all paintings for employees with less than 10 year of experience, because Oracle Entitlements Server will automatically deny if there is no matching policy. OEG Policy The OEG policy looks like the following The 11g Authorization filter configuration is similar to :  The ${PAINTING_NAME} and ${USER_EXPERIENCE} variables are initialized by the "Retrieve from the HTTP header" filters for testing purpose. That's to say, under Service Explorer, we need to provide 2 attributes "Experience" & "Painting" following the OES 11g Authorization filter described above.

    Read the article

  • What are common uses of condition variables in C++?

    - by jasonline
    I'm trying to learn about condition variables. I would like to know what are the common situations where condition variables are used. One example is in a blocking queue, where two threads access the queue - the producer thread pushes an item into the queue, while the consumer thread pops an item from the queue. If the queue is empty, the consumer thread is waiting until a signal is sent by the producer thread. What are other design situations where you need a condition variable to be used?

    Read the article

  • Over-Current condition on port 7 or 8

    - by Dymatic
    I am having a problem with my USB ports. It shows over-current conditions on ports 7 and 8. I have heard that this is caused by a damaged USB port, and since it is detecting it on two ports it seems that I have two that are broken. I do indeed have two that do not work, so that is not the issue. What I would like to do is disable whatever program is running over-current condition checks. tty's are unusable at this point. Every few second a new over-current condition occurs. Here is the output of dmesg: http://pastebin.com/CuFKRGue Is there an easy way to disable these checks or damage the ports to a point where it will no longer check? Fixing them is not important or an option.

    Read the article

  • Wait on multiple condition variables on Linux without unnecessary sleeps?

    - by Joseph Garvin
    I'm writing a latency sensitive app that in effect wants to wait on multiple condition variables at once. I've read before of several ways to get this functionality on Linux (apparently this is builtin on Windows), but none of them seem suitable for my app. The methods I know of are: Have one thread wait on each of the condition variables you want to wait on, which when woken will signal a single condition variable which you wait on instead. Cycling through multiple condition variables with a timed wait. Writing dummy bytes to files or pipes instead, and polling on those. #1 & #2 are unsuitable because they cause unnecessary sleeping. With #1, you have to wait for the dummy thread to wake up, then signal the real thread, then for the real thread to wake up, instead of the real thread just waking up to begin with -- the extra scheduler quantum spent on this actually matters for my app, and I'd prefer not to have to use a full fledged RTOS. #2 is even worse, you potentially spend N * timeout time asleep, or your timeout will be 0 in which case you never sleep (endlessly burning CPU and starving other threads is also bad). For #3, pipes are problematic because if the thread being 'signaled' is busy or even crashes (I'm in fact dealing with separate process rather than threads -- the mutexes and conditions would be stored in shared memory), then the writing thread will be stuck because the pipe's buffer will be full, as will any other clients. Files are problematic because you'd be growing it endlessly the longer the app ran. Is there a better way to do this? Curious for answers appropriate for Solaris as well.

    Read the article

  • Checking negative of a condition

    - by oym
    What is the (slightly pejorative) term for checking the negative of a condition (rather than the positive which is often more readable): e.g. if(!someVar) { return null; } else { return doSomethingInteresting(); } instead of doing this (which is arguably more readable) if(someVar) { return doSomethingInteresting(); } else { return null; } I vaguely remember there being a term for this; something in the same spirit as the term Yoda conditions.

    Read the article

  • Do condition variables still need a mutex if you're changing the checked value atomically?

    - by Joseph Garvin
    Here is the typical way to use a condition variable: // The reader(s) lock(some_mutex); if(protected_by_mutex_var != desired_value) some_condition.wait(some_mutex); unlock(some_mutex); // The writer lock(some_mutex); protected_by_mutex_var = desired_value; unlock(some_mutex); some_condition.notify_all(); But if protected_by_mutex_var is set atomically by say, a compare-and-swap instruction, does the mutex serve any purpose (other than that pthreads and other APIs require you to pass in a mutex)? Is it protecting state used to implement the condition? If not, is it safe then to do this?: // The writer protected_by_mutex_var = desired_value; some_condition.notify_all(); With the writer never directly interacting with the reader's mutex? If so, is it even necessary that different readers use the same mutex?

    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

  • Can i make a launcher shortcut perform different actions based on a condition

    - by Nirmik
    What i want to do is pretty simple to understand. I want the same launcher shortcut to act like a ON/OFF swith for eg. Like suppose i have made a launcher to start LAMPP with the command gksudo /opt/lampp/lampp start This works properly to start lampp. Now,what i want to do is,If LAMPP is not on,the launcher should execute the above command and start lampp.While if lampp is on,I want ti to execute the command gksudo /opt/lampp/lampp stop and stop lampp. I want these 2 commands to be executed by the same launcher where the command to be executed is decided on the basis of a condition(LAMPP being ON or OFF in the above example) Can i do this? and how? I guess writing a bash script and then making the launcher execute the bash script would do it.but then how do i check weather lampp is on of off?

    Read the article

  • SUM condition on one set of columns where another includes certain values

    - by pjp
    I have the following data in Excel where I want a formula that will give me the sum of all of the total rows: A B australia 10 australia total 10 china 1 china 5 china 7 china total 13 I have tried formulae along the lines of =sumif(A:A,"search("total",A:A)>0",B:B) but I cannot get the condition to work. What is the correct way to write this contains condition? Is there also specific a grammar for the condition language? I've been unable to find anything.

    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

  • Detect an Uninstall in a Launch Condition using Wix MSIs

    - by coxymla
    I've been playing around with Wix, making a little app with auto-generated installer and three versions to test the upgradability, 1.0, 1.1 and 2.0. 1.1 is meant to be able to upgrade from 1.0, and not to allow the user to install 1.1 if 1.1 is already present. <Upgrade Id="F30C4129-F14E-43ee-BD5E-03AA89AD8E07"> <UpgradeVersion Minimum="1.0.0" IncludeMinimum="yes" Maximum="1.0.0" IncludeMaximum="yes" Property="OLDERVERSIONBEINGUPGRADED" /> <UpgradeVersion Minimum="1.1.0" IncludeMinimum="yes" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" /> </Upgrade> <Condition Message="A later version of [ProductName] is already installed. Setup will now exit."> NOT (NEWERVERSIONDETECTED OR Installed) </Condition> Problem #1: 1.1 can't be uninstalled, because the condition is set and checked during the uninstall. 2.0 is meant to be able to upgrade from 1.1, and not to upgrade from 1.0 ('too old'.) It shouldn't be able to install on top of itself either. <Upgrade Id="F30C4129-F14E-43ee-BD5E-03AA89AD8E07"> <UpgradeVersion Minimum="1.1.0" IncludeMinimum="yes" Maximum="1.1.0" IncludeMaximum="yes" Property="OLDERVERSIONBEINGUPGRADED" /> </Upgrade> <Upgrade Id="F30C4129-F14E-43ee-BD5E-03AA89AD8E07"> <UpgradeVersion Minimum="2.0.0" OnlyDetect="yes" Property="NEWERVERSIONDETECTED" /> </Upgrade> <Upgrade Id="F30C4129-F14E-43ee-BD5E-03AA89AD8E07"> <UpgradeVersion Minimum="1.0.0" IncludeMinimum="yes" Maximum="1.0.0" IncludeMaximum="yes" Property="TOOOLDVERSIONDETECTED" /> </Upgrade> <Condition Message="A later version of [ProductName] is already installed. Setup will now exit."> NOT NEWERVERSIONDETECTED OR Installed </Condition> <Condition Message="A version of [ProductName] that is already installed is too old to be upgraded. Setup will now exit."> NOT TOOOLDVERSIONDETECTED </Condition> Problem #2: If I try to upgrade from 1.1, I hit my modified later version condition. (Error: A later version of Main Application 1.1 is already installed. Setup will now exit.) Problem #3: The installer allows me to install 2.0 over the top of itself. What am I doing wrong with my Upgrade code and conditions to get these problems in my MSIs?

    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

  • 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

  • PowerPivot FILTER condition optimizations

    - by Marco Russo (SQLBI)
    In the comments of a recent post from Alberto Ferrari there was an interesting note about different performance related to the order of conditions in a FILTER call. I investigated about that and Jeffrey Wang has been so nice to give me some info about actual implementation that I can share on a blog post. First of all, an important disclaimer: PowerPivot is intended to make life easier, not requiring the user to think how to write the order of elements in a formula just to get better performance....(read more)

    Read the article

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