Quantcast
Channel: User user695652 - Stack Overflow
Browsing latest articles
Browse All 35 View Live

Comment by user695652 on std::thread thread spun off in object, when does it...

I see, though I still don't understand how I would correctly terminate my thread in the destructor, yield woudl not work because my thread runs in an endless loop.

View Article



Comment by user695652 on std::thread thread spun off in object, when does it...

@kfsone thanks for the comment. Could you specify a bit more on which undefined behavior thread(&Bar::foo, this) is reliant on

View Article

Comment by user695652 on Terminating an std::thread which runs in endless loop

@ NathanOliver But if I detach it and the thread accesses member fields of Bar the behaviour would be undefined after the Bar instance gets destructed

View Article

Comment by user695652 on Terminating an std::thread which runs in endless loop

@Holt thanks for your answer. I have one question: What do you mean by You use an std::atomic<bool> to control the loop;?

View Article

Comment by user695652 on subtraction from size_t results in large positive...

@ Borgleader one of those annoying "remove trailing whitespace situations" when concatenating strings

View Article


Comment by user695652 on template deduction evaluates to overload of...

@Jon McClung, thanks for your comment. I would like to use the one with double.

View Article

Comment by user695652 on template deduction evaluates to overload of...

thanks for your answer. Could you expand it a bit, I don't see how I can call bar with a non double value in your approach.

View Article

Comment by user695652 on template deduction evaluates to overload of...

@marcinj I think I undestand W.F. comment but why exactly do we need template<int=0> ?

View Article


Comment by user695652 on Terminating a shell script bar from a script foo

Nice solution, thanks! Once question: in the stop section, shouldn't we delete the pidfile as the last instruction? Otherwise we would always end up in the echo "$pidfile exists." case

View Article


Comment by user695652 on C++ Ensure that subclasses provide a custom value...

@ Richard Critten But how do you ensure that the prio is constant for each object of a class?

View Article

std::sort descending order with operator overloading

I have an std::vector of object for which I overloaded the < operator. How can I use std::sort to sort it in descending order (without needing to write my own Comparator)?

View Article

std::unordered_map test if specific Foo key is present

I have an unordered map of Foo objects and I would like to efficiently test, if the key set contains of Foo objects with a given id. One way would be to construct a Foo object and set it's id to the...

View Article

Template specialization with empty brackets and struct

I am used to the template syntax of the form struct hash<template class Key> but what is the difference when using template <> struct hash<Key> ?namespace std { template <>...

View Article


Smart Pointers and non-copyable member fields

After reading quite a bit about (smart)-pointers in the context of class members, I am still not sure how to handle to follwoing situation. I want to create objects of type Foo, either by calling the...

View Article

Wrapping std::map and provide pointer to element

I am using a library which offers a function foo(Widget*).My Widgets are stored in struct WidgetManager { std::map<int, Widget> dict; ??? getWidget(int id);}Originally I stored (raw) Widget...

View Article


C++11: Default constructor: Implicit or Explicit? [closed]

When am I supposed to use the default keyword in C++11?Is it now considered bad to writestruct Foo {};and one should writestruct Foo { Foo() = default;};?

View Article

Understanding Simple Race Condition example

I'm very new to multithreaded programming and I don't quite understand why exactly I am getting the following outputs in different runs of the code below. run 1:http://bar => fake content http://foo...

View Article


Given sorted vector find transition from negative to positive

Given a sorted std::vector<int>, I would like, using C++11-STD functions, to find the index where the elements transition from negative to positive.I am aware that I can implement this using a...

View Article

Using std::async in constructor

I am quite new to the C++11 feature std::async and I fail to grasp why the code below never prints bar. Could someone shed some light on this for me?class Thready { public: Thready() {...

View Article

Inserting an object having a non copyable field into an std::vector

I understand that the following code does not compile since the move constructor of A is deleted because the mutex is not movable.class A { public: A(int i) {} private: std::mutex m;};int main() {...

View Article

std::map of non-movable objects [duplicate]

Related to my previous question: Inserting an object having a non copyable field into an std::vectorIt seems that I can have a map storing non-movable objects Aonly if A is default constructable. Is...

View Article


How long is std::async running?

If I create an std::async object in a class, how long does the corresponding thread run? Until the desctructor of the containing class (Bar) is called? class Bar {public:Bar() { handle = std::async(...

View Article


Reference to return value of function [duplicate]

I am confused whether in the following snippet foo is guaranteed to be valid, i.e., whether I am allowed to store function return values as const references? I am asking because the return value is...

View Article

threadsafety vs Iterator validity

I have two threads:Thread A inserting into an std::mapThread B removing from an std::mapSince std::map::erase and std::map::insert keep all iterators of the map valid, I don't seem to understand how a...

View Article

Is master always redis instance with smallest priority?

I am running master-slave redis with sentinel, when I kill my master, the lowest priority slave becomes the new master. But when I start my old master again, which has an even lower priority, it does...

View Article


Terminating a shell script bar from a script foo

I have a script foo which, if provided an argument start, starts, among other things a script bar in the background and exits - bar contains an infinite loop. At a later stage, I want to call foo with...

View Article

Include std library in header or cpp?

If I have a class A which uses iostream, should I put the include statement of iostream in A.h or A.cpp?

View Article

Why no variable size array in stack?

I don't really understand why I can't have a variable size array on the stack, so something likefoo(int n) { int a[n];}As I understand the stack(-segment) of part of the data-segment and thus it is not...

View Article

Motivation for not using virtual functions [duplicate]

I hope this question is not too vague, but coming from java, I can not think of any reason why I would use non-virtual functions in C++. Is there a nice example which demonstrates the benefit of...

View Article



Semicolon after Function

Is there a specific reason why some people put a semicolon after the curly closing function bracket?void foo() {};

View Article

cost function in cv.glm of boot library in R

I am trying to use the crossvalidation cv.glm function from the boot library in R to determine the number of misclassifications when a glm logistic regression is applied. The function has the following...

View Article

Scope vs. Lifetime of Variable

What is the relation between the scope and the lifetime of a variable?If a variable is out of scope, is the memory of it allowed to be overwritten by another variable, or is the space reserved until...

View Article

How to know which malloc is used?

The way I understand it, there exist many different malloc implementations:dlmalloc – General purpose allocatorptmalloc2 – glibcjemalloc – FreeBSD and Firefoxtcmalloc – Googlelibumem – SolarisIs there...

View Article


What's the difference between _int_malloc and malloc (in Valgrind)

I am amazed that I can't find any document stating the difference between _int_malloc and malloc in the output of Valgrind's callgrind tool.Could anybody explain what's their difference? Furthermore, I...

View Article

Define variable b of the same type as variable a

Is it possible to declare a variable var_b of the same type as another variable, var_a?For example:template <class T>void foo(T t) { auto var_a = bar(t); //make var_b of the same type as...

View Article
Browsing latest articles
Browse All 35 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>