Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #103860

Re: Memory not updating in thread as expected

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: Memory not updating in thread as expected
Date Tue, 14 Feb 2017 09:44:47 +0100
Organization A noiseless patient Spider
Lines 49
Message-ID <o7ufui$upl$1@dont-email.me> (permalink)
References <s023ac5gl1bpefvi63upl7tb6iunf0a8mo@4ax.com> <d52fe51a-1f8d-47fe-9283-5f1c13f5a05d@googlegroups.com> <ggg3acdd9s4h3p47f4488mns89opglousv@4ax.com> <o7tb2c$40o$1@dont-email.me> <o7ts13$d40$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
Injection-Date Tue, 14 Feb 2017 08:42:58 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="4df052af8d348a45e32c6627b112b120"; logging-data="31541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xJc9YsRMqht82FqAn5nAVjGLMxO6cTAA="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <o7ts13$d40$1@dont-email.me>
Cancel-Lock sha1:JcyluvNFplGIY38ez2h6+TUTA2Q=
Xref csiph.com comp.lang.c:103860

Show key headers only | View raw


On 14/02/17 04:04, James Kuyper wrote:
> On 02/13/2017 05:15 PM, David Brown wrote:
> ...
>> You are programming on Linux here.  Linux supports a wide array of 
>> mutexes, semaphores, and other synchronisation systems that /work/.  You 
>> will have to learn to use them, and not try to invent your own with a 
>> bit of "volatile" here and there - you /will/ get this wrong.
> 
> You sound like you have some idea how to do this kind of thing (which is
> more than I could say about myself). I'd prefer (particularly in this
> newsgroup) sticking strictly to C2011's new threading library, rather
> than making any use of anything Linux-specific. Could you (or anyone
> else who cares to do so) show us the right way to do something like the
> OP's original code? 

Not me, I'm afraid.  I know enough to know the OP is wildly up the wrong
track, and I know enough to know how big my own gaps are here - I
haven't written such code on Linux in C and would need to learn the
details myself.  (I've written Linux multi-threading code in Python, and
multi-threading code in C on small embedded systems, but not on Linux.)

To be honest, I am far from convinced that the C11 threading stuff is
useful.  The atomics can be useful (though hard to understand), but
threading is too specific to the OS in question - an abstraction like
<threads.h> is not a good match.  For Linux, you want support for
standard mutexes, fast mutexes, spinlocks, read-write locks, etc. - a
library that gives you only simple condition variables and mutexes is
not enough.  But if <threads.h> tried to cover these, it would not match
with the Windows equivalents, and be different from the vxWorks
versions, and the RTEMS locks.  And the functions that /are/ covered in
<threads.h> don't fit efficiently with the underlying functions.  If you
are using FreeRTOS on a 16-bit microcontroller, you want to specify your
timeouts in a uint16_t of milliseconds - not "struct timespec" objects
with conversions back and forth with calendar dates and nanoseconds.

> He didn't provide a complete program, or any context
> for that code, so feel free to make reasonable choices about what the
> context would actually look like, without making it excessively
> complicated. str1[0] seems to be being used solely for the purpose of
> synchronizing execution of the two threads, and the rest of the
> allocated memory is not used at all, so feel free to drop the allocated
> memory entirely, and use the most appropriate method to achieve that
> synchronization.
> 
> I'm not just asking this on the OP's behalf - I've little experience
> with this kind of code, and none of it recent, and therefore none of it
> using C2011 - so I'd like to see it for myself.
> 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 12:46 +0200
  Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 05:18 -0800
    Re: Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 16:25 +0200
      Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 10:30 -0800
        Re: Memory not updating in thread as expected Jerry Stuckle <jstucklex@attglobal.net> - 2017-02-13 14:30 -0500
  Re: Memory not updating in thread as expected m.labanowicz@gmail.com - 2017-02-13 05:46 -0800
    Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-13 14:30 +0000
      Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-13 15:13 -0800
    Re: Memory not updating in thread as expected Test <test@.nil.invalid.com> - 2017-02-13 16:36 +0200
      Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-13 23:15 +0100
        Re: Memory not updating in thread as expected James Kuyper <jameskuyper@verizon.net> - 2017-02-13 22:04 -0500
          Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-14 09:44 +0100
            Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 11:07 +0000
              Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-14 12:46 +0100
                Re: Memory not updating in thread as expected Robert Wessel <robertwessel2@yahoo.com> - 2017-02-16 05:12 -0600
                Re: Memory not updating in thread as expected David Brown <david.brown@hesbynett.no> - 2017-02-16 12:44 +0100
              Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 15:53 +0100
                Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 15:36 +0000
                Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 17:58 +0100
                Re: Memory not updating in thread as expected Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-14 17:26 +0000
          Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 10:43 +0100
            Re: Memory not updating in thread as expected Robert Wessel <robertwessel2@yahoo.com> - 2017-02-14 03:52 -0600
              Re: Memory not updating in thread as expected Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2017-02-14 11:36 +0100
              Re: Memory not updating in thread as expected supercat@casperkitty.com - 2017-02-14 05:31 -0800
  Re: Memory not updating in thread as expected Ken Brody <kenbrody@spamcop.net> - 2017-02-13 12:44 -0500
  Re: Memory not updating in thread as expected Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-02-13 10:58 -0700
  Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-14 15:13 -0800
    Re: Memory not updating in thread as expected "Chris M. Thomasson" <invalid@invalid.invalid> - 2017-02-14 16:37 -0800

csiph-web