Search Results

Search found 8397 results on 336 pages for 'implementation'.

Page 26/336 | < Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >

  • Lockless queue implementation ends up having a loop under stress

    - by Fozi
    I have lockless queues written in C in form of a linked list that contains requests from several threads posted to and handled in a single thread. After a few hours of stress I end up having the last request's next pointer pointing to itself, which creates an endless loop and locks up the handling thread. The application runs (and fails) on both Linux and Windows. I'm debugging on Windows, where my COMPARE_EXCHANGE_PTR maps to InterlockedCompareExchangePointer. This is the code that pushes a request to the head of the list, and is called from several threads: void push_request(struct request * volatile * root, struct request * request) { assert(request); do { request->next = *root; } while(COMPARE_EXCHANGE_PTR(root, request, request->next) != request->next); } This is the code that gets a request from the end of the list, and is only called by a single thread that is handling them: struct request * pop_request(struct request * volatile * root) { struct request * volatile * p; struct request * request; do { p = root; while(*p && (*p)->next) p = &(*p)->next; // <- loops here request = *p; } while(COMPARE_EXCHANGE_PTR(p, NULL, request) != request); assert(request->next == NULL); return request; } Note that I'm not using a tail pointer because I wanted to avoid the complication of having to deal with the tail pointer in push_request. However I suspect that the problem might be in the way I find the end of the list. There are several places that push a request into the queue, but they all look generaly like this: // device->requests is defined as struct request * volatile requests; struct request * request = malloc(sizeof(struct request)); if(request) { // fill out request fields push_request(&device->requests, request); sem_post(device->request_sem); } The code that handles the request is doing more than that, but in essence does this in a loop: if(sem_wait_timeout(device->request_sem, timeout) == sem_success) { struct request * request = pop_request(&device->requests); // handle request free(request); } I also just added a function that is checking the list for duplicates before and after each operation, but I'm afraid that this check will change the timing so that I will never encounter the point where it fails. (I'm waiting for it to break as I'm writing this.) When I break the hanging program the handler thread loops in pop_request at the marked position. I have a valid list of one or more requests and the last one's next pointer points to itself. The request queues are usually short, I've never seen more then 10, and only 1 and 3 the two times I could take a look at this failure in the debugger. I thought this through as much as I could and I came to the conclusion that I should never be able to end up with a loop in my list unless I push the same request twice. I'm quite sure that this never happens. I'm also fairly sure (although not completely) that it's not the ABA problem. I know that I might pop more than one request at the same time, but I believe this is irrelevant here, and I've never seen it happening. (I'll fix this as well) I thought long and hard about how I can break my function, but I don't see a way to end up with a loop. So the question is: Can someone see a way how this can break? Can someone prove that this can not? Eventually I will solve this (maybe by using a tail pointer or some other solution - locking would be a problem because the threads that post should not be locked, I do have a RW lock at hand though) but I would like to make sure that changing the list actually solves my problem (as opposed to makes it just less likely because of different timing).

    Read the article

  • Is this implementation truely tail-recursive?

    - by CFP
    Hello everyone! I've come up with the following code to compute in a tail-recursive way the result of an expression such as 3 4 * 1 + cos 8 * (aka 8*cos(1+(3*4))) The code is in OCaml. I'm using a list refto emulate a stack. type token = Num of float | Fun of (float->float) | Op of (float->float->float);; let pop l = let top = (List.hd !l) in l := List.tl (!l); top;; let push x l = l := (x::!l);; let empty l = (l = []);; let pile = ref [];; let eval data = let stack = ref data in let rec _eval cont = match (pop stack) with | Num(n) -> cont n; | Fun(f) -> _eval (fun x -> cont (f x)); | Op(op) -> _eval (fun x -> cont (op x (_eval (fun y->y)))); in _eval (fun x->x) ;; eval [Fun(fun x -> x**2.); Op(fun x y -> x+.y); Num(1.); Num(3.)];; I've used continuations to ensure tail-recursion, but since my stack implements some sort of a tree, and therefore provides quite a bad interface to what should be handled as a disjoint union type, the call to my function to evaluate the left branch with an identity continuation somehow irks a little. Yet it's working perfectly, but I have the feeling than in calling the _eval (fun y->y) bit, there must be something wrong happening, since it doesn't seem that this call can replace the previous one in the stack structure... Am I misunderstanding something here? I mean, I understand that with only the first call to _eval there wouldn't be any problem optimizing the calls, but here it seems to me that evaluation the _eval (fun y->y) will require to be stacked up, and therefore will fill the stack, possibly leading to an overflow... Thanks!

    Read the article

  • Drag and drop an image from desktop to a web text editor (implementation in javascript)

    - by fatmatto
    I tried to write reasonably short title but i failed i guess.. Hi everybody here's what i'm trying to do: I want to implement a web text editor able to recognize when the user drag a image file over it's editing surface and it automa(gically) starts the upload and insert the image near the cursor position. In other words i don't want the user to do the usual "insert-image-browse-ok". Atm i am not very good at javascript ... i know JQuery but i have not a clear idea about how to implement this... i don't know if there's an event handler able to help me in this situation... if not then there should be i think or web apps would miss some kind of interactivity. I've heard miracles about HTML5 could it help me? I've seen such things in Google Wave but that surface doesn't seem to be a form field... google lab's black magic i guess.... Thank you in advance.

    Read the article

  • Pointer-based binary heap implementation

    - by Derek Chiang
    Is it even possible to implement a binary heap using pointers rather than an array? I have searched around the internet (including SO) and no answer can be found. The main problem here is that, how do you keep track of the last pointer? When you insert X into the heap, you place X at the last pointer and then bubble it up. Now, where does the last pointer point to? And also, what happens when you want to remove the root? You exchange the root with the last element, and then bubble the new root down. Now, how do you know what's the new "last element" that you need when you remove root again?

    Read the article

  • Best pageable table implementation in GWT

    - by Steve Buikhuizen
    I need to add a paging, sortable table to my GWT application. I see lots of these out there so I'm looking for your experience to save me time by choosing the best one. So far I'm looking at... http://code.google.com/p/gwt-advanced-table/ http://code.google.com/p/google-web-toolkit-incubator/wiki/PagingScrollTableOld I like the second one best. Any stories to tell?

    Read the article

  • Which Queue implementation to use in Java?

    - by devoured elysium
    I need to use a FIFO structure in my application. It needs to have at most 5 elements. I'd like to have something easy to use (I don't care for concurrency) that implements the Collection interface. I've tried the LinkedList, that seems to come from Queue, but it doesn't seem to allow me to set it's maximum capacity. It feels as if I just want at max 5 elements but try to add 20, it will just keep increasing in size to fit it. I'd like something that'd work the following way: XQueue<Integer> queue = new XQueue<Integer>(5); //where 5 is the maximum number of elements I want in my queue. for (int i = 0; i < 10; ++i) { queue.offer(i); } for (int i = 0; i < 5; ++i) { System.out.println(queue.poll()); } That'd print: 5 6 7 8 9 Thanks

    Read the article

  • Cross-Browser jQuery text-zoom implementation

    - by JMC Creative
    I've got some code to increase/decrease font size. This is giving me a headache because each browser seems to implement the $.css('font-size') differently (see jquery bug). The part that's really killing me, though, is that Firefox is scaling up okay, but when I use the scale down function below, it scales up. Webkit & IE are both working as expected. Any ideas on that? I put this in a fiddle here: http://jsfiddle.net/srQ3P/1/ where you can see it working as expected, and you can see it broken in firefox at the project page: http://cumberlandme.info/residents MAJOR EDIT Sorry, the issue is not the code, it's firefox buggy behavior. After I zoom in or out with the browser controls (ctrl + plus or ctrol + minus) the js goes haywire. This doesn't happen in other browsers. This is the real issue. Any advice on that

    Read the article

  • AutoComplete implementation - Interview Question

    - by user181218
    Hi, Say you have a DB table with two cols: SearchPhrase(String) | Popularity(Int). You need to initialize a DS so that you could use it to implement an autocomplete feature (like google suggest) comfortably. The requirement: Once the data from the db is processed into the data structure, when you type a letter you get the 10 most popular searchphrases from the db starting with that letter,then when you type the next one you get the 10 .... with these two letters and so on. The question only concerns planning the ds and pseudocoding Insert,Search etc. Note: YOU CANNOT USE TRIE DS. Any ideas?

    Read the article

  • Differences between matrix implementation in C

    - by tempy
    I created two 2D arrays (matrix) in C in two different ways. I don't understand the difference between the way they're represented in the memory, and the reason why I can't refer to them in the same way: scanf("%d", &intMatrix1[i][j]); //can't refer as &intMatrix1[(i * lines)+j]) scanf("%d", &intMatrix2[(i * lines)+j]); //can't refer as &intMatrix2[i][j]) What is the difference between the ways these two arrays are implemented and why do I have to refer to them differently? How do I refer to an element in each of the arrays in the same way (?????? in my printMatrix function)? int main() { int **intMatrix1; int *intMatrix2; int i, j, lines, columns; lines = 3; columns = 2; /************************* intMatrix1 ****************************/ intMatrix1 = (int **)malloc(lines * sizeof(int *)); for (i = 0; i < lines; ++i) intMatrix1[i] = (int *)malloc(columns * sizeof(int)); for (i = 0; i < lines; ++i) { for (j = 0; j < columns; ++j) { printf("Type a number for intMatrix1[%d][%d]\t", i, j); scanf("%d", &intMatrix1[i][j]); } } /************************* intMatrix2 ****************************/ intMatrix2 = (int *)malloc(lines * columns * sizeof(int)); for (i = 0; i < lines; ++i) { for (j = 0; j < columns; ++j) { printf("Type a number for intMatrix2[%d][%d]\t", i, j); scanf("%d", &intMatrix2[(i * lines)+j]); } } /************** printing intMatrix1 & intMatrix2 ****************/ printf("intMatrix1:\n\n"); printMatrix(*intMatrix1, lines, columns); printf("intMatrix2:\n\n"); printMatrix(intMatrix2, lines, columns); } /************************* printMatrix ****************************/ void printMatrix(int *ptArray, int h, int w) { int i, j; printf("Printing matrix...\n\n\n"); for (i = 0; i < h; ++i) for (j = 0; j < w; ++j) printf("array[%d][%d] ==============> %d\n, i, j, ??????); }

    Read the article

  • Implementation of APIs on diferent platforms

    - by b-gen-jack-o-neill
    OK, this is basicly just about any non-default OS API running on all different OS. But for my example let´s consider platform Windows, API SDL (Simple DirectMedia Layer). Actually this question came to my mind when I was reading about SDL. Originally, I thought that on Windows (and basicly any other OS) you must use OS API to make certain actions, like wrtiting to screen, creating window and so on, becouse that API knows what kernel calls and system subroutines calls it has to do. But when I read about SDL, I surprised me, becouse, you cannot make computer to do anything more than OS can, since you cannot acess HW directly, only thru OS API, from Console allocation to DirectX. So, my question actually is, how does this not-default-OS APIs work? Do they use (wrap) original system API (like MFC wraps win32 api)? Or, do they actually have direct acess to Windows kernel? Or is there any third, way in between? Thanks.

    Read the article

  • Interface that Entails the Implementation of Indexer

    - by Ngu Soon Hui
    I am looking for a framework-defined interface that declares indexer. In other words, I am looking for something like this: public interface IYourList<T> { T this[int index] { get; set; } } I just wonder whether .Net framework contains such interface? If yes, what is it called? You might ask why I can't just create the interface myself. Well, I could have. But if .Net framework already has that why should I reinvent the wheel?

    Read the article

  • C++ option/long option implementation

    - by K Hein
    I am working on a parser for meta programming language using C++ on Linux platform. Right now, I need to implement option/long option for the parser to provide some additional features. Basically, if the user pass in some additional option, the parser needs to store statistics while parsing the text files. I can think of two ways to implement it. One way is to user global to store options entered by users. Another way is to create a singleton class to store options. So I would like to know if there is any other way to implement it. What is the best/most recommended way of implementing it? Thanks in advance. Regards, K.Hein

    Read the article

  • Facebook implementation in android

    - by Sanat Pandey
    I am implementing Facebook in my app through FbRocket jar, but it gives some error as ClassNotFound, but I don't know why bcoz i have alredy added that jar in libraries........ Please help me out. 05-09 19:04:28.933: ERROR/AndroidRuntime(759): FATAL EXCEPTION: main 05-09 19:04:28.933: ERROR/AndroidRuntime(759): java.lang.NoClassDefFoundError: net.xeomax.FBRocket.FBRocket 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at org.shopzilla.android.moretab.SettingActivity.shareFacebook(SettingActivity.java:73) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at org.shopzilla.android.moretab.SettingActivity$2.onClick(SettingActivity.java:63) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.view.View.performClick(View.java:2485) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.view.View$PerformClick.run(View.java:9080) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.os.Handler.handleCallback(Handler.java:587) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.os.Handler.dispatchMessage(Handler.java:92) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.os.Looper.loop(Looper.java:123) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at android.app.ActivityThread.main(ActivityThread.java:3683) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at java.lang.reflect.Method.invokeNative(Native Method) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at java.lang.reflect.Method.invoke(Method.java:507) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-09 19:04:28.933: ERROR/AndroidRuntime(759): at dalvik.system.NativeStart.main(Native Method) Code: package org.shopzilla.android.moretab; import java.util.List; import net.xeomax.FBRocket.FBRocket; import net.xeomax.FBRocket.Facebook; import net.xeomax.FBRocket.ServerErrorException; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.shopzilla.android.common.R; import org.shopzilla.android.facebook.FacebookActivity; import org.shopzilla.android.facebook.FacebookWebOAuthActivity; import org.shopzilla.android.twitter.TwitterActivity; import org.shopzilla.android.twitter.TwitterWebOAuthActivity; import twitter4j.http.RequestToken; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class SettingActivity extends Activity{ String bytesSent; HttpClient httpclient; int count1; // List with parameters and their values List<NameValuePair> nameValuePairs; TextView mText; Button btn_facebook; Button btn_twitter; FBRocket fbRocket; RequestToken rToken; String oauthVerifier; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.more_setting); Button btn_twitter = (Button)findViewById(R.id.btn_more_setting_twitter); Button btn_facebook = (Button)findViewById(R.id.btn_More_setting_facebook); btn_twitter.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(SettingActivity.this,TwitterActivity.class); startActivity(intent); //displayTwitterAuthorization(); } }); btn_facebook.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub /*Intent intent = new Intent(SettingActivity.this,FacebookActivity.class); startActivity(intent);*/ shareFacebook(); //displayFacebookAuthorization(); //shareFacebook(); } }); } public void shareFacebook() { fbRocket = new FBRocket(SettingActivity.this, "ShopZilla", "172619129456913"); if (fbRocket.existsSavedFacebook()) { fbRocket.loadFacebook(); } else { fbRocket.login(R.layout.facebook); } } public void onLoginFail() { fbRocket.displayToast("Login failed!"); fbRocket.login(R.layout.facebook); } public void onLoginSuccess(Facebook facebook) { // TODO Auto-generated method stub fbRocket.displayToast("Login success!"); try { facebook.setStatus("This is your status"); fbRocket.displayDialog("Status Posted Successfully!! " + facebook.getStatus()); } catch (ServerErrorException e) { if (e.notLoggedIn()) { fbRocket.login(R.layout.facebook); } else { System.out.println(e); } } } }

    Read the article

  • Fastest implementation of the frac function in C#

    - by user349937
    I would like to implement a frac function in C# (just like the one in hsl here http://msdn.microsoft.com/en-us/library/bb509603%28VS.85%29.aspx) but since it is for a very processor intensive application i would like the best version possible. I was using something like public float Frac(float value) { return value - (float)Math.Truncate(value); } but I'm having precision problems, for example for 2.6f it's returning in the unit test Expected: 0.600000024f But was: 0.599999905f I know that I can convert to decimal the value and then at the end convert to float to obtain the correct result something like this: public float Frac(float value) { return (float)((decimal)value - Decimal.Truncate((decimal)value)); } But I wonder if there is a better way without resorting to decimals...

    Read the article

  • Ajax with Jsf 1.1 implementation

    - by Rohan Ved
    I am using JSF1.1 in that, have this code_ <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="http://www.azureworlds.org" prefix="azure"%> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="x"%> <%@ taglib uri="http://www.asifqamar.com/jsf/asif" prefix="a"%> ... <x:selectOneMenu value="#{hotelBean.state}"> <f:selectItem itemLabel="Select One" itemValue="" /> <f:selectItem value="#{hotelBean.mapStates }" /> <x:ajax update="city" listener="#{hotelBean.handleCityChange}" /> </x:selectOneMenu> <h:outputText value="City* " /> <x:selectOneMenu id="city" value="#{hotelBean.city}"> <f:selectItem itemLabel="Select One" itemValue="" /> <f:selectItem value="#{hotelBean.mapCities }" /> </x:selectOneMenu> line x:ajax update="city" listener="#{hotelBean.handleCityChange}" is not working , i searched but got JSF1.1 not support for Ajax. then what can i do for this? and i have less knowledge of JS. Thanx

    Read the article

  • Help me understand Dispose() implementation code from MSDN

    - by Benny
    the following code is from MSDN: Idisposable pattern protected virtual void Dispose(bool disposing) { // If you need thread safety, use a lock around these // operations, as well as in your methods that use the resource. if (!_disposed) { if (disposing) { if (_resource != null) _resource.Dispose(); Console.WriteLine("Object disposed."); } // Indicate that the instance has been disposed. _resource = null; _disposed = true; } } why the following statement: _resource = null; _disposed = true; are not enclosed by if (disposing) statement block? for me i would probably write like this: if (disposing) { if (_resource != null) { _resource.Dispose(); _resource = null; _disposed = true; } Console.WriteLine("Object disposed."); } anything wrong with my version?

    Read the article

  • "requiresuniqueemail=true" implementation in asp.net site

    - by domineer
    Hi people I got a social networking site that is running live right now.The first time I launched my site I let requiresuniqueemail=false set-up on my web.config inorder for me to create dummy accounts for testing purposes and to start up the site you know.However the site is kind of stable right now w/ almost 5k members.So I would like to set-up the requiresuniqueemail to true so that users cannot reuse their existing email address and for me to make it sure that there will be unique email ad for each site user.I know the site got like 100 users with the same email address.My question is what could be the problem I'm going to face if I do this right now(requiresuniqueemail="true") and how to do this efficiently(without errors and if possible sitewide say in the global assax)?I tested and I already got an error if I logout an account.Like say a user try to click log-out this code runs: Dim d As DateTime = DateTime.Now.AddMinutes(-1 * Membership.UserIsOnlineTimeWindow) Dim theuser As MembershipUser = Membership.GetUser() theuser.LastActivityDate = d Membership.UpdateUser(theuser) If Not Cache(Page.User.Identity.Name.ToLower() + "currentstatus") Is Nothing Then Cache.Remove(Page.User.Identity.Name.ToLower() + "currentstatus") End If Then an exception occured on updateuser() function saying System.Configuration.Provider.ProviderException: The E-mail supplied is invalid. This is just one instance I know that I encountered a problem. Hoping to hear your ideas guys.....

    Read the article

  • Is this a correct implementation of singleton C++?

    - by Kamal
    class A{ static boost::shared_ptr<A> getInstance(){ if(pA==NULL){ pA = new A(); } return boost::shared_ptr(pA); } //destructor ~A(){ delete pA; pA=NULL; } private: A(){ //some initialization code } //private assigment and copy constructors A(A const& copy); // Not Implemented A& operator=(A const& copy); // Not Implemented static A* pA; }; A* A::pA = NULL;

    Read the article

  • coffee scrip layzy function implementation

    - by bbz
    I would like to something like this in JavaScript var init = function () { // do some stuff once var once = true // overwrite the function init = function () { console.log(once) } } CoffeeScript adds another local var init to the initial init so the second init doesn't overwrite the first one var init = function () { var init //automatically declared by coffeescript // do some stuff once var once = true // overwrite the function init = function () { console.log(once) } } Some tips for solutions / workarounds would be greatly appreciated.

    Read the article

  • Getting below error when trying to register a generic class with a implementation using .net 2.0

    - by Gaurav Saxena
    Code: StructureMapConfiguration.BuildInstancesOf().AsSingletons().TheDefaultIsConcreteType(); Error: StructureMap Exception Code: 190 Can not create a Generic PluginFamily for PluginFamily MIGExcel.Service.IPersistenceService1[[MIGExcel.Model.Contact, WizardModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. Check that the basic type MIGExcel.Service.IPersistenceService1 is configured as a PluginFamily. These Generic types are configured within StructureMap as PluginFamily's: MIGExcel.Service.IPersistenceService`1[[MIGExcel.Model.Contact, WizardModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],MIGExcel.Service;

    Read the article

  • Implementation code for GetDateFormat Win32 function

    - by morpheous
    I am porting some legacy code from windows to Linux (Ubuntu Karmic to be precise). I have come across a Win32 function GetDateFormat(). The statements I need to port over are called like this: GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'January', 31); OR GetDateFormat(LOCALE_USER_DEFAULT, 0, &datetime, "MMMM", 'May', 30); Where datetime is a SYSTEMTIME struct. Does anyone know where I can get the code for the function - or failing that, tips on how to "roll my own" equivalent function?

    Read the article

  • Implementation problem. Htaccess in php

    - by Irwan
    I have a problem to fix the URL on my website at http://www.abelputra.com I need a solution: I want to change www.abelputra.com/software.php into www.abelputra.com/software I have read a tutorial like this: For .htaccess: RewriteEngine On RewriteRule ^ ([a-zA-Z0-9_-] +) $ index.php? Key = $ 1 RewriteRule ^ ([a-zA-Z0-9_-]+)/$ index.php? Key = $ 1 Then in php: index.php --- $Key=$ _GET ['key']; if ($key == 'home') { include ('index.php'); // Home page } else if ($ key == 'software') { include ('software.php'); // } else if ($ key == 'webdesign') { include ('webdesign.php'); // } The problem is: When I implemented the menu software.php index.php to call the page: www.abelputra.com/index.php?key=software what happens is the page that is shown is two pages later software.php index.php page underneath. Is it because calling functions "include ()"? index.php structures: Header Content - contains the opening words Footer software.php structure: Header Content - contains an explanation of my software Footer Sorry my english bad. im from Indonesia. Please solution .. thanks

    Read the article

< Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >