« first day (519 days earlier)      last day (3797 days later) » 
00:00 - 20:0020:00 - 00:00

00:08
0
Q: crawl multiple pages at once

Ralphupdate from:Basic search engine I want to process multiple pages at once pulling url's from tier_list in the crawl_web method. The problem I am having is crawl_web already has 2 threads to crawl and index simultaneously, the .join() seems to prevent opening more than one page. import urllib2, c...

00:54
hey 2nd Monitor, Long time!
Hey!
1
Q: Sort three input values by order

DaveThis is a program to sort three inputted integers in order, from least to greatest. I would like to have it reviewed. #include <iostream> void Sort(int &a, int &b, int &c){ if(a>b){ int tmp = a; a = b; b = tmp; } if(a>c){ int tmp = a; a=c; ...

01:08
yo !
Any python guys here?
few things I like about LaTeX
1) Not Ms Word or It's Clone
2) Works nicely with Git
3) tex.stackexchange.com
4) Flawlessly working on Fedora 20
@Anirudh need more Python,R,... reviewers
Do you think Python can replace Java? @JaDogg
01:15
Right, I don't know how people who have worked in Java before switch to python without screwing up their JAVA knowledge
haha
01:35
@Mat'sMug thank you for the info.
what all can I do with Visual Studio Express? the free version?
I'm using Express 2013 at work, and I can do everything I need to do - from Console / WinForms / WPF applications (VSE for Desktop), to ASP.NET / MVC if I wanted (VSE for Web), and because I also have SQL Server Data Tools I also use it to develop SSRS reports, and if I had a non-express SQL Server license I could also use it to build SSAS cubes and SSIS ETL's.
VS Express only doesn't support lots of plugins - like ReSharper, and Productivity Power Tools
it's tooling is also relatively limited compared to other editions.
@Malachi ^
@Mat'sMug I don't currently use a lot of that stuff.
I need to start looking for a job in Tennessee.... my In-Laws sold there house up here and we want to be closer to them than we would be if we stayed
somebody stop me, I'm going all out with supporting "attributes" in VBA!
'@TestInitialize
Public Sub Prepare()

    LogManager.UnregisterAll
    If Not mock Is Nothing Then Set mock = Nothing
    If Not mock2 Is Nothing Then Set mock = Nothing

    expectedLevel = -1
    expectedLogger = vbNullString
    expectedMessage = vbNullString

End Sub
sorry I just saw what @Morwenn wrote like 7 hours ago about jobs looking for him...lucky guy
hmm I missed that.. congratulations @Morwenn!
01:47
A Man, A Plan, A Canal: Panama
02:21
sleeping. TTGTB here - ciao @all!
02:40
LAters. TTGTB here too!!!
02:58
0
Q: Improving the performance of Linq based solution

user843681Again, out of fun on saturday night, I decided to solve the following problem from CodeEval. The problem is finding the lowest unique number. https://www.codeeval.com/open_challenges/103/ Suppose you're given a set of numbers from players for the round of game. E.g. 2 rounds of the game look ...

03:44
Is anyone familiar with the PlantUML plugin in NetBeans?
03:58
Hi
You're familiar with it?
Nope, sorry.
But, if you ever need moar Google Fu power, I'll be glad to help.
Ah, okay. I can't seem to find any resources on getting started with it.
HaleOS enters protected mode
Virtualbox implodes. GG.
why am I the first to upvote this....
1
A: Expected error can only be a 440/Automation Error?

retailcoderI don't know what's special about custom error codes in VBA. But if the error numbers thrown in the SUT are not in the form of the recommended vbObjectError + n (as can be inferred from the -2147220406 representation of the error code you're expecting), then any application-defined or object-def...

04:13
What's with all the tax questions
Is this a joke? Or is it international tax day?
@EngieOP I was retagging them with a new tag.
I see.
*Quietly returns to Rancho Relaxo*
Did you read about the new TF2 spectate patch?
Volvo, y u do dis? :L
04:49
@rolfl Yes, my wife and I both love Person of Interest, and she's a mundane.
definitely one of my favorite shows
05:03
1
Q: Secure password hashing implementation

Mike D.I'm implementing a password hashing method for a website. The code below is part of the User class. Any pointers on what I could do better? private string GenerateSalt(int SaltLength) { using (var rng = new RNGCryptoServiceProvider()) { var salt_bytes = new byte[SaltLength]; ...

 
1 hour later…
06:10
1
Q: Subnetting calculator in Go

eric_lagergrenWhenever I try to learn a new language, I write a subnetting calculator. Here's my attempt with Go. In particular, I think I'm not writing idiomatic Go, as well as abusing float64(), uint64(), etc. My math should be correct, although I might have goofed when trying to translate JavaScript's num...

06:44
@200_success I should add the , right?
07:01
If you are deliberately writing code to solve a problem that a common library can do, sure.
Oh the other hand, there's little to gain by adding the tag after three people have already pointed out the reinvention.
little > nothing
thanks for the review btw, it should get more upvotes
1
A: Parsing command line arguments in Perl

200_successAs more than one user has already noted, you are reinventing-the-wheel. Nevertheless, the code is worth reviewing. Using the & sigil to call a subroutine has gone out of style since Perl 5 was released in 1994. Nesting a for-loop inside a while-loop is a weird way to express the flow of contro...

0
Q: Adding list of customcontrols

MaxThis is the basic class that I am trying to display: public class Day { public DateTime Date { get; private set; } public SpecialDay SpecialDay { get; set; } public DateTime TimeIn { get; private set; } public DateTime TimeOut { get; private set; } public DayOfWeek DayOfW...

07:59
0
Q: Implementing a Linked List

Amr AymanI am studying Data Structures at the moment, so I want to see if there is anything wrong with my implementation of linked lists in C, after I checked the arraylist/vector implementation .. This is the header #ifndef _LINKEDLIST_H #define _LINKEDLIST_H #include <stddef.h> /* size_t */ #include <...

@Mat'sMug Thank you :)
08:56
And to all, a good monking!
09:23
@Jamal Oh...lol, oops.
Thanks for the edit though.
0
Q: Optimizing run time of Python solution to Project Euler Problem 34

REACHUSThis is a brute force solution to Project Euler Problem 34 with only 1 optimization (i.e.: caching factorials): import time, math start = time.time() total = 0 # Cache factorials factorials = [math.factorial(x) for x in xrange(0,10)] range_end = 7 * factorials[9] for i in range(3,range_end+1)...

0
Q: WeatherForecastRequest and its builder

Leonid SemyonovWeatherForecastRequest is only simple HTTP parameters wrapper. It is using to get forecast from the openweathermap. At first here is utility class (used to simplify actions to post request, receive response and convert it to String): // import packages from org.apache.http.*** public class Htt...

10:03
Monking
Is there some way I can split reward my bounty?
Yep. Don't award it.
Let it award itself and it should split.
> If you do not award your bounty within 7 days (plus the grace period), the highest voted answer created after the bounty started with a minimum score of 2 will be awarded half the bounty amount.
Oh, I thought that it would plit. My bad :/
I should've read the help pages before asking here :p
I thought putting a bounty would make it easier for me to decide what is the best answer
Twitter is horrible... I want to be updated on news of something, but there's just so much junk coming by
11:01
0
Q: regular expression - match only specified string length

j-oI'm learning re. Here I'm checking a string of type aA1 but want also to check it is only 3 characters long. Is there a better way of doing it please? str = raw_input("input in form 'aA1' please >") check = re.compile("[a-z][A-Z][0-9]") if len(str) == 3: validate = check.match(str) if v...

11:16
Parallel buils really do make a difference with compile times.
@Morwenn Coding in C++ I guess?
@skiwi Always.
Yeah then it matters a lot
I was one of the reasons I wanted a quadcore.
About my farmer worker question, should you in C be using lots of methods? Or is that not best practice, and what about C++?
11:19
Monster methods are almost never a good idea. And this guideline holds for many languages.
In C I find it very difficult to pass parameters, etc. Especially because it is not object-orientated
There's just so many memory loopholes you open when passing stuff around as a beginner
In C++, one method = one responsability, and if it involves state, you put it into a class.
Well I was comparing C++ and C there, I shouldn't have
In C, you put data into structures then write free methods to manipulate the structures. You pass them to functions by pointer.
Career-wise, is it feasible to forget about coding in C as fast as possible and concentrate only on C++? While still keeping pointers, etc. in mind of C
I think non-OOP-and-non-functional languages are horrible for programming large applications
11:25
The probem is that many jobs require not to use some specific parts of C++, and you will often have to use C libraries or to deal with C-like C++.
Generally speaking, writing modern C++ is the classier thing you can do, but you will often have to deal with old third-party code that looks like C, so you can't really forget about C.
11:40
Aw... that's a bit sad
But in C++ you can at least write wrapper libraries around the old C code, right?
You can, but using directly the C library ensures that you will mostly encounter known errors. And you are paid to use a library, not to write a wrapper around it.
Yep. Not much point to putting a wrapper around toupper() for example.
There is already a standard one.
But for a full string :p
I've been looking for examples of C++ exception use in embedded systems. Nobody has yet confessed to using them in a real embedded project yet.
I think that means no STL either.
@Morwenn: by the way, congratulations on the new laptop. Do you feel powerful? :)
The problem with exceptions on embedded systems is not the runtime cost (zero unless triggered) but the size of the allocated buffer used to implement them.
@Edward I don't feel powerful, but the aptop sure does :p
11:47
I think writing wrappers around C functionality still has its place
It still has it place for sure, but when you write some production software, you also have there are also costs for the maintainance of the wrapper.
@Morwenn Yes, exactly.
sure, but I think it's a tradeoff vs how ugly using the C library as-is will be
From a beauty point of vue, I am 100% for writing C++ wrappers. But I understand that you can't always afford to do this/
sure, but personally, I'd probably push for it more often that not
get someone that understands the C layer well to write it
and you can potentially save yourself a world of hurt (and memory leaks)
11:52
Also, the problem is that even people who know the C layer will need to learn how to use the C++ one.
Unless you open-source it and manage to have it adopted by the World.
And some libraries are simply hopeless. The GTK+ library, for example.
The problem with C++ is that there isn't any widely adopted modern GUI library.
screw it, write the GUI in Python :P
At least you didn't say "write the GUI in Java"
dear god no
11:56
@Yuushi Well, when I want to write GUI stuff, I use PySide actually.
When I want to write GUI stuff, I lie down until the urge subsides.
@Morwenn Yeah, current project I'm working on is pyqt (their choice, not mine).
We really need a C++ GUI library that does not reimplement half of the standard library...
it would be nice
Also, Qt isn't even real C++. It is a pain to compile.
And the guidelines of wxWidgets are... well...
> Formally _WX prefix makes this prefix a reserved word, however this style is used in wxWidgets since 20+ years and hasn't created any problems so far, so we are going to continue using it.
> We could like, remove the leading underscore, that could be done in less than a day, but we prefer to stick to ill-formed code, just in case.
2
> Don't use exceptions, don't use RTTI, don't use many standard library classes, don't use new logical operators keywords.
Actually, the guidelines evolved recently. A few months earlier, there were also "don't use templates, don't use namespaces".
And a subtle "don't use C++" hidden somewhere in the guidelines.
12:08
even if it isn't said directly, it's pretty-much implied
> Lock-Free Programming (or, Juggling Razor Blades)
^^ I think that I will read these slides.
12:20
@Morwenn Thanks for posting a link to them the other day. I'm looking forward to reading them.
yeah, I've started downloading the videos they're uploading to youtube. Need to find some time to watch them :/
I've got about 5 hours on passenger jets tomorrow, so I'll have plenty of time.
@Edward You can thank @rolfl for accepting to pin them. Most of the people here won't be interested in reading them :)
Yeah yeah
@Donald ... we are hooked, watched 7 episodes since Friday.
Reading up... aws afka bit
12:32
@rolfl Did you say... Friday?
@Morwenn I'm interested in reading them... But no interest x time for it :(
@Morwenn I did, watched 3 on Friday Night, and 4 last night
12:52
I have to go (rehearsal), see you later :)
Music or acting?
Music. Folk metal.
@Morwenn I'm more of a funk sax player, but I'd love to hear your stuff.
When is the world tour?
@Edward When we will be offered enough to travel abroad.
@Morwenn :) Fair enough. I'll let you go.
12:57
Hmm... is a regular division (in C) on two integers the same as the div operation?
It truncates the decimal part, so I'm guessing yes
    #include <stdio.h>

    int main()
    {
        printf("7 / 5 = %d\n", 7/5);  /* this prints 1 */
        return 0;
   }
Not sure what you mean when you refer to "the div operation" but if you divide two integers, you get an integer result.
@JeroenVannevel I'm gong to watch it now, but I bet that is what I always wanted!
It is. It most definitely is.
@Edward Well, talking about i div 64, as written in an assignment, in mathematical terms
13:05
Math.sin() is one powerful expression.
@JeroenVannevel Ok, that is freaking awesome!
@skiwi It would be floor(a/b)
@Edward What's the difference with regular division?, as I think truncating is equal to flooring on ints?
@JeroenVannevel And again, it gave me a whole new definition of live coding!
Can you imagine building a game and actually be immersed right into it?
@JeroenVannevel Yes, I am doing that right now!
(Imagining, that is)
13:17
car.Spawn() and suddenly you're inside a car
@skiwi regular division would say that 7/5 = 1.4 but with integers, it's 1.
0
Q: Haskell monad- and error-handling-style

BladtAs an answer to excersise 2.3 in Chris Okasaki's book, Purely Functional Data Structures, I've written the following haskell implementations of insertion in a binary heap: import Data.Maybe data Tree e = Leaf | T (Tree e) e (Tree e) deriving Show empty = Leaf insert x Leaf = T Leaf x Leaf ins...

Hmm, in C should you use functions or defines for oneliners?
int is_prime = BIT_IS_SET(buffer[j / 64], j % 64);
@skiwi There's no single correct answer for that. Generally, I would use functions, but macros are often easier. It's easier to troubleshoot functions and there are fewer surprises.
See this SO question for an example.
@200_success i think you can help on this.
@200_success please provide your comments on this query
13:28
Ah that's tricky yes, I was already wondering why the macros in the template file where defined in parenthesis, but I thought it just looked neater, as I also use parenthesis around say return (i <= 5);
@skiwi I generally teach programmers NOT to put parentheses around a returned value because return is a statement and not a function call.
I also generally say not to use macros, but some are too handy not to use. One I often use in C++ for troubleshooting is this:
#define SHOW(X) std::cout << # X " = " << (X) << std::endl;
13:44
@Edward Well say in Java practically no one puts spaces between the method call and arguments, so there's no confusion, I would say
@Edward That's actually quite nice
Yes, it's quite handy for stuff like this:
SHOW(std::numeric_limits<double>::min_exponent10);
That prints: "std::numeric_limits<double>::min_exponent10 = -307"
at least it does on this machine.
In Netbeans I can press, in key combinations: "soutv", Tab, expression name
soutv + Tab is System.out.println("" = ), with a caret both for the variable name inside the string, and behind the = operator
similar problem; similar solution
Except here it's not programmed in the code, it's not that I dislike macros, but it opens the way to a whole new type of badly written programs in Java if ever implemented
I don't generally use an IDE or a debugger, so naturally I have different methods.
13:52
No IDE? :(
Most of my work involves embedded systems.
An IDE is less effective when the I/O is a single green LED.
I also tend to use a number of different processors and compilers, so I'd have to switch among fifteen completely different IDEs (when it's even an option) -- not a productivity enhancer!
I would tend to disagree, but I don't do embedded programming, so I don't know
How many different IDEs do you currently use?
Also, I want to clarify something I wrote earlier. In C, with integers a/b isn't quite exactly floor((double)a/b).
Specifically when one of the numbers is negative, you may get different results, e.g. -8/16 = 0 but floor(-8.0/16.0) = -1.
The Python folks have recently addressed this
14:09
0
Q: JavaScript Hide and Show via Class

user3772340I have a question, I want to hide field sets on selected option. But doesn't work Can you help me ? var fieldset = document.querySelector('fieldset:nth-of-type(2)'); var fieldset1 = document.querySelector('fieldset:nth-of-type(3)'); var fieldset2 = document.querySelector('fieldset:nth-of-type(4)...

 
1 hour later…
15:36
@Edward Just Netbeans here, have some experience with others but not using them
@Edward Okay... that's interesting, I am here only working with positive numbers by designt hough
@skiwi If you can use just one IDE, it's almost certainly a productivity gain. Much less so if you have to switch among many different ones, each with their own quirks and idioms.
Ah I see
Interesting:
> You have to write a threaded prime generator, based on the Sieve of Eratosthenes. In the wiki page, the algorithm is fully sequential: first all multiples of 2 are struck out, then the multiples of 3 are struck out, then .. etc.

In this assignment however, those activities have to be done in parallel: one thread strikes out the multiples of 2, and (at the same time!) another thread strikes out the multiples of 3, etc. The 'list of numbers' (as mentioned in the wiki) is shared between all threads, so access to this datastructure must be protected by mutexes.
How can I implement this in a threaded way if getting the next prime number depends on the computations of the previous threads?
The only way to know that a number is a prime number, is by waiting until the Sieve of Eratosthenes has been computed for that prime number (unless you do naive prime checking, but that defeats the point of using the Sieve)
Striking out multiples of 2 and multiples of 3 are independent operations, right?
So they can be done in parallel
@Edward How so?
The striking itself is independent, yes
But in order to know that 3 is a prime, you want to have computed the Sieve of Eratosthenes on a grid of size 3
(Means you struck out 2)
@skiwi Yes. That means that to know that n is prime, the code must have struck out all up to sqrt(n).
You might find inspiration in this question on CR
15:47
0
Q: Android - AsyncTask and IntentService

BobI was disappointed using GCM, so I'll use long polling for crucial parts. Following my approach: protected void onCreate(Bundle savedInstanceState) { new LongPolling().execute(); } private class LongPolling extends AsyncTask<String, Void, String> { @Override protected String doInB...

0
Q: Byte swapping functions

d3lByte Swapping functions: #include <stdint.h> uint16_t _bswap16(uint16_t a) { a = ((a & 0x00FF) << 8) | ((a & 0xFF00) >> 8); return a; } uint32_t _bswap32(uint32_t a) { a = ((a & 0x000000FF) << 24) | ((a & 0x0000FF00) << 8) | ((a & 0x00FF0000) >> 8) | ((a & 0xFF000000)

I'm still a bit confused on it
I presume you'd be given some upper cap. So the program might be asked "calculate all primes less than one million."
Correct
I've made the sequential version, now I'm first doing the next part of the assignment:
> implement the Sieve without parallelism but with threads: the main() function has a for-loop, and in each iteration a thread is started which strikes out the multiples of the next prime. The for-loop waits until the thread has been finished.
Which is quite straight-forward
So you could have a "strike multiples of 2 less than 1e6" thread and a "strike multiples of 3 less than 1e6" thread, etc. -- the program is done when all threads finish.
@Edward Yes, but you can only start the strike out multiples of 3 once (strike out multiples of 2 | less than 9) finished?
(As before that you do not know that 3 is a prime)
Maybe the implementation of the algorithm is wrong:
    //start striping out multiples of primes
    int p;
    for (p = 2; p <= sqrt(NROF_SIEVE); p++)
    {
	while (!IS_PRIME(p))
	{
	    p++;
	    continue;
	}

	pthread_t thread;
	pthread_create(&thread, NULL, strike_out_multiples, (void*)p);
	pthread_join(thread, NULL);
    }
16:13
Ah, I see what you mean now. Yes, when all threads striking out numbers have completed up to n you'll have the primes up to n.
One way to "cheat" is to start out with a few known primes, e.g. {2, 3, 5, 7} will allow you to calculate all of the primes up to 100.
0
Q: Palindrome check in Haskell

daniilI am learning Haskell and I am doing 99 Haskell problems. There is a problem to check if a list if a palindrome. It's obvious solution is isPalindrome x = x == reverse x There are several other solutions with some kind of reverse. All of them use two passes -- one for building reverse list and...

0
Q: how to create a program that generates random numbers in an array.

AnettCould anyone help with creating a program that generates random numbers from 100 to 1000, each number can only be picked once, see which number is the smallest and largest and the mean, the number closest to the mean, and use import javax.swing.JOptionPane and Random. The array should have about ...

16:43
0
Q: DESIGNING Time class in c++

user3198508Problem Statement: 1. Design a class TIME which stores hour, minute and second. The class should have the methods to support the following: User may give the time value in 24-hour format. User may give the time value in AM/PM format Display the time in 24-hour format. Display the time in AM/PM fo...

> and now I feel as if I've learned two things today and I don' thave pants on yet.
Well, three things if you count "the neighbors prefer that I wear pants when fetching the morning paper."
@Edward I'm wondering how to "fix" it though for parallel computing as I'm ensure how you can wait until X is prime, because it might never become a prime
I see the cheating way, but we need to support for arbitrary maxima
My new computer compiles in < 1min15s what took 10 to 15 minutes to compile with my old computer.
That's what I would call an improvement.
@Morwenn Nice! and old ouch
@Morwenn You're the parallel Sieve of Eratosthenes expert around here, right?
16:50
@skiwi I tried to write one once.
@skiwi Can you assume to begin with that you know that 2 is prime?
I can't really give you more insight than what you can find in my old questions and the associated answers.
@Morwenn: yes, I pointed to it about an hour ago.
There was a follow-up. I don't know whether you looked at it or not.
The follow-up code didn't have any data race, but it wasn't great either.
@Edward I suppose that would be allowed
16:57
Actually, 2 isn't a prime.
A prime is a number that is only dividable by 1 and by itself... I think it qualifies
Just kidding, don't go refactoring your code yet.
You didn't make me nervous there the slightest bit ;)
Lol @Morwenn, you named your striking out function also strike_out_multiples
I neded up deleting it in the latest version of my code. The one that was not on CR. Also, the one that disappeared with my previous hard drive.
I have to go (once again), see you later :)
@Morwenn Github? :(
17:09
Hello @EngieOP
Hello :P
@skiwi Did that bounty expire?
0
Q: Cross-domain with requirejs text plugin

Frederic Naultthere is my implementation for cross domain call using the requireJs text plug-in htaccess file in the template folder of my cross-domain site Header set Access-Control-Allow-Origin "*" textremote.js define(['text','module'],function (text, module) { // Load the cross-domain url from th...

@syb0rg I'm about to award it, the bounty itself is not there anymore though
Check the 2nd result :)
Still stuck with that assignment, really wondering if I am taking a complicated route or something
Or well if I have N threads, then I can calculate primes sequentially until I know there are N primes, and then I can parallelize the striking out, but it doesn't look nice
17:27
Here's a possible strategy. Start with 2 and strike out until you get to 2^2. Everything not crossed out (just 3 in this case) is prime, so you can start the next thread. So strike out 3 until you get to 3^2 at which point you have "discovered" 5 and 7. Spawn two more threads, etc.
@Edward In this case how would you notify to the main program once it striked out 4, use a mutex or something?
Yes, each access of the array would need to be protected by a mutex.
@Edward That I understand, but in some way you also need to notify the main thread about "until you get to 2^2"
@overexchange Please do not badger an individual user to answer your Stack Overflow question, especially when using a Code Review chat room. That's two faux pas.
I don't know why you singled me out, given…
May 20 at 11:06, by 200_success
FYI, I had on my list of tags to ignore for some time.
@skiwi The simplest way would be to simply set up the threads so that they terminate when they reach the square of the currently highest known prime.
As each thread terminates, you know new primes.
17:36
But say I need to calculate the sieve of 4000... Then the thread striking the 2's would terminate once it striked 4?
Yes, and then you could relaunch it to go from 5 through 4000.
Currently trying to get some arraylist/queue equivalent in C, but seems like not much is provided in the standard libraries
@Edward Ah, once it is done, I see that now
I could allocate memory for NROF_THREADS threads, that might work
Alternatively, it could go from 2 through 4000 and launch its own sub thread once it passed 2^2.
That might be cleaner and easier to code.
Would using a mutex also be fine? Or is that not clean
You'll still need a mutex if all threads access the same array.
That's the part that Morwenn's code did not include but should have, as I recall.
17:50
I am actually working on code, and I am not at Work!!! I love it! Learn Learn Learn!
18:01
@Malachi That's what I like about this profession. There is always lots more to learn.
Of course the down side is that I feel perpetually ignorant...
2
@Edward I might have found the key to solving it
/**
 * buffer[]: datastructure of the sieve; each number is represented by one bit
 */
static unsigned long long   buffer [(NROF_SIEVE/64) + 1];
> In the last step, buffer[] will be accessed by several threads at the same time. So you must ensure that access is done under mutual exclusion.
The buffer is basically a buffer of individual bits, disguised in blocks of 64 bits
I cannot put a mutex on every read & write of the buffer though, because then parallelization would not have any effect
Oh, so I guess you're going to use a mutex just on individual blocks.
That's how it sounds like it should be
I don't know yet where it would help me, but I will need to use it to complete this assignment
It's in C rather than C++?
I'm not sure yet where to put the mutex
Yep, all in C89 or C90
Striking out elements in the buffer surely does not need a mutex
18:07
Can you use Posix threads?
Yes, that's what we need to use
So only a mutex is needed when reading from the buffer
You need a mutex when reading or writing.
@Edward I hear that....
-1
Q: linked list using c++ with separate node class and linked list class

user3198508Problem statement:Create a class for linked list. Consider a separate class NODE for basic node activities and use it in class for linked list. #include<iostream> #include<cstdlib> using namespace std; class node { public: int data; node *link; }; class linklist { node *p; ...

^^^ noooo! not another linked list!
3
18:09
@Edward That deserves more than one star!
But what do I want to use the mutex against? I want to use it to prevent that the next prime is being read before it has been striked out
Lol
2
Let's assume you have common code to translate from bit number to block.
The mutex would be inside that code, and done by block.
But I only need the mutex for searching the next prime in the main loop, right?
Because once I print all primes, I have joined all threads either way
@Edward But this one is broken (aren't they all). ;-)
@Jamal Not all of them. This one is positively brilliant.
@skiwi You'll need to lock the mutex each time you want to read or write a block and then release it when that's done.
you could either have one mutex for the whole array (not very clever) or have one for each block (takes much more memory).
I'd probably start by writing it the non-clever way just to get it working.
18:35
Aren't segfaults great
@Edward But does that automatically solve the problem of finding the next prime?
I'm just wondering about this: If I lock a read of prime 2 with a mutex, will I then not be unable to write to it until I unlock it?
@skiwi If one thread has a lock asserted, then no other thread will be able to access it until the resource is unlocked.
So concretely, say that your "cross out multiples of 2" thread asserts a lock on the first block
It could assert a lock, process all of the bits within that block, and release the block.
OR it could assert and release the block for every bit access.
Once you get above 64, it will amount to the same thing anyway.
I'll do it for bit accesses now for sure
I still fail to see how it fixes the problem, but will implement either way as it is simply neccessary
If all threads access a "high water mark" then you can know where there primes are located.
So if the cross out by x threads are all at or above x^2, you know that all unmarked numbers in that range are prime.
Use another mutex for that high water mark.
Off-by-one errors suddenly got a whole lot more annoying in C, fixed it though
I may actually not fully understand how mutexes work... Need to fix that first
18:49
So I've been thinking about mutexes as to be locking and unlocking the resource per call, but it is per thread then
So when using a mutex it will naturally make sure that setting up the first few threads is slow, and then it speeds up as more primes are known
You've got it.
MONKING!
Hola
Monking @Phrancis
One more question for now @Edward
static pthread_mutex_t buffer_mutexes[(NROF_SIEVE / 64) + 1];

int main (void)
{
    //initialize mutexes
    int mi = 0;
    for (mi = 0; mi < (NROF_SIEVE / 64) + 1; mi++)
    {
	buffer_mutexes[mi] = PTHREAD_MUTEX_INITIALIZER;
    }
What am I doing wrong here?
> In file included from prime.c:15:0:
prime.c: In function ‘main’:
prime.c:55:23: error: expected expression before ‘{’ token
buffer_mutexes[mi] = PTHREAD_MUTEX_INITIALIZER;
^
That ^ should be pointed at the P
I don't really see the issue there, the compiler does though.
Other than the missing closing }, I don't see an error. Have you #included the relevant pthread bits?
19:01
@Edward I believe to have included it, will double check, what about the missing closing }?
Oh from the main you mean... well, the full main doesn't fit ;)
Got a fix on it
2
Q: C pthread mutex: Expected expression before `{'

aoakI am using pthread library to create two threads. I am using two queues to communicate the data between the two threads (producer-consumer thing) and hence want to have a mutex to sync the push-pops in the queue by the threads. The problem I am facing is, I get a compile error as follows: $ gcc...

Uh... what, the compiler does not complain at this?
static int read_buffer_safe(int element)
{
    rsleep(100);
    pthread_mutex_lock(&buffer_mutexes[element / 64]);
    return BIT_IS_SET(buffer[element / 64], element % 64);
    pthread_mutex_unlock(&buffer_mutexes[element / 64]);
}
@skiwi I take it back. I see a few errors. You're going to need to call pthread_mutex_init() because PTHREAD_MUTEX_INITIALIZER is only available at compile time.
@Edward The cast-version also works seemingly
No, that won't work because you can only use that for statically declared mutexes.
Your loop should be like this: pthread_mutex_init(&buffer_mutexes[mi], NULL);
Anyone here who can help with speeding up a for loop with core data?
@Edward Somehow it does seem to work, but I'll change it
19:13
@MichaelShamash Could be, what do you have?
Am I allowed to link to my CodeReview question here?
@MichaelShamash Absolutely.
I suppose it's safe to ignore the fatal exceptions in logcat when the app can suddenly start up again
@JeroenVannevel Ignoring fatal exceptions... no problem
19:17
@skiwi Don't forget to check the return value for pthread_mutex_init()
@Edward let me know if you have any questions of if I should clarify something
@MichaelShamash I think the question is clearly stated, but I'm not an Objective-C guy so can't help much with this one.
@Edwawrd , ah, ok. Thanks anyway :)
@MichaelShamash No problem. I upvoted the question, so it will get attention eventually.
@MichaelShamash if you only paste the link URL as a chat message, the chat system will one-box it:
2
Q: Speeding up this Core Data storage code

Michael ShamashI am using this code to read a huge file (10MB, about 200000lines) and break it up into its different components. Once broken up, it saves it into core data with one to many relationships for use later on. How can I speed up this code? It currently takes several minutes for this to run on my iPa...

19:21
@Edward, thx
@Mat'sMug, oh, very cool!
works with Wikipedia and XKCD links, too :)
@Mat'sMug And really, what else would one conceivably reference?
lol
2
@MichaelShamash Is the data fixed, i.e. the same data loaded into Core Data each time the application starts? In that case you can create the Core Data sqlite file on your Mac once and distribute that with your application.
19:23
@Edward I've got it "working", I think I'll leave it from here, it currently does not do the mutex when reading the next prime, but it doesn't seem to be an issue in the test runs I did
I figure it will only cost 1 or 2 points and I can see how awake the teacher is
"lol" detected .... star applied
2
@MartinR , Yes, it is fixed. I actually do that now with other data but the data does change once a month or so, so it would require a re-downlload of the sqlite file and then somehow to replace the active one with the new one...
I was thinking if it'd be better to re-process this data once a month on the user's device of me to do it and upload to the server the sqlite file which the app will download
3
Q: Speeding up this Core Data storage code

Michael ShamashI am using this code to read a huge file (10MB, about 200000lines) and break it up into its different components. Once broken up, it saves it into core data with one to many relationships for use later on. How can I speed up this code? It currently takes several minutes for this to run on my iPa...

19:26
^^ and that's @CaptainObvious, late again :)
2
Haha
@MartinR are you an Obj C developer?
> You are obliged to place calls to function rsleep() at strategic places in your code (e.g. inside a for-loop of the thread, but not inside a critical section, each time when reading data from (or writing data to) buffer[]).
Does this mean that I can place a function call to rsleep() when reading or writing data to buffer[]?
0
Q: "Guess a number b/w 1 and 100" game

felicitysmoakSo for my AP CS class, we were to make a guessing game, where the user has to guess a number between 1 and 100. I've already got that part down. The teacher also wanted us to add extra stuff, like having the user type in their name and tell them if they need to guess higher or lower. I've also go...

19:43
What's the best way to keep my core data objects that i created in the same order so when I retrieve them they are in that order? Same data file as here: http://codereview.stackexchange.com/questions/64809/speeding-up-this-core-data-storage-code
It cannot be alphabetical since there is no order like that in the file, these are coordinates on a line which need to be in this order.
Core Data does not preserve the order of objects added to the store. You have to add a sort descriptor to the fetch request, using some attribute of your entity.
So i should create a new attribute then called for example 'id' with a numeric value?
Yes.
I see, thank you. :)
00:00 - 20:0020:00 - 00:00

« first day (519 days earlier)      last day (3797 days later) »