Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Re: C Code Perfect Storm of Stupid

Thu Jan 25, 2018 12:13 pm

just brew it! wrote:
johnrreagan wrote:
On our platform (OpenVMS), our ctime() implementation actually allocates a mutex-locked, thread-specific buffer and then calls ctime_r() effectively deprecating ctime().

Why is a mutex needed when the buffer is thread-specific? That seems overly paranoid to me, and could even result in deadlocks if ctime() is used from a signal handler.

I was thinking the same thing. Plus the fact that a mutex can be very expensive. Lock-free methods might be better here, if possible.

On the other hand, lock-free coding is much more complex to reason about, so just going with the mutex is generally less buggy, even if slower.
 
SecretSquirrel
Minister of Gerbil Affairs
Posts: 2726
Joined: Tue Jan 01, 2002 7:00 pm
Location: North DFW suburb...
Contact:

Re: C Code Perfect Storm of Stupid

Fri Jan 26, 2018 1:22 am

Buub wrote:
just brew it! wrote:
johnrreagan wrote:
On our platform (OpenVMS), our ctime() implementation actually allocates a mutex-locked, thread-specific buffer and then calls ctime_r() effectively deprecating ctime().

Why is a mutex needed when the buffer is thread-specific? That seems overly paranoid to me, and could even result in deadlocks if ctime() is used from a signal handler.

I was thinking the same thing. Plus the fact that a mutex can be very expensive. Lock-free methods might be better here, if possible.

On the other hand, lock-free coding is much more complex to reason about, so just going with the mutex is generally less buggy, even if slower.


A lot of it depends on how its implemented and/or how thread local storage if implemented on the system, if the buffer is truly thread specific and not just one per thread. Lock free is good, but unless ctime() is called in performance critical code (which would be silly, in my mind), then take the mutex performance penalty and don't worry about whether the lock free code is correct and/or adding yet another library dependency.

--SS
 
just brew it!
Administrator
Topic Author
Posts: 54500
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

Re: C Code Perfect Storm of Stupid

Fri Jan 26, 2018 7:33 am

SecretSquirrel wrote:
Buub wrote:
just brew it! wrote:
Why is a mutex needed when the buffer is thread-specific? That seems overly paranoid to me, and could even result in deadlocks if ctime() is used from a signal handler.

I was thinking the same thing. Plus the fact that a mutex can be very expensive. Lock-free methods might be better here, if possible.

On the other hand, lock-free coding is much more complex to reason about, so just going with the mutex is generally less buggy, even if slower.

A lot of it depends on how its implemented and/or how thread local storage if implemented on the system, if the buffer is truly thread specific and not just one per thread. Lock free is good, but unless ctime() is called in performance critical code (which would be silly, in my mind), then take the mutex performance penalty and don't worry about whether the lock free code is correct and/or adding yet another library dependency.

TBH what bugs me the most about it is that now you've got OpenVMS devs who are potentially writing code which will break in subtle ways (in spite of compiling without warnings) if it is ever ported to another OS. By "fixing" a runtime library function which has existed for decades, OpenVMS has introduced a hidden incompatibility.
Nostalgia isn't what it used to be.
 
Glorious
Gerbilus Supremus
Posts: 12343
Joined: Tue Aug 27, 2002 6:35 pm

Re: C Code Perfect Storm of Stupid

Fri Jan 26, 2018 4:03 pm

https://threadreaderapp.com/thread/9490 ... 78050.html

Article wrote:
As a consumer of raw code, you'll witness software behaving in surprising ways, ways which even we as developers couldn't have anticipated. That's exciting to me. Bold


Personally, I've never experienced richer, warmer bugs.
 
Buub
Maximum Gerbil
Posts: 4969
Joined: Sat Nov 09, 2002 11:59 pm
Location: Seattle, WA
Contact:

Re: C Code Perfect Storm of Stupid

Fri Jan 26, 2018 4:19 pm

Glorious wrote:
https://threadreaderapp.com/thread/949070111083778050.html

Article wrote:
As a consumer of raw code, you'll witness software behaving in surprising ways, ways which even we as developers couldn't have anticipated. That's exciting to me. Bold


Personally, I've never experienced richer, warmer bugs.

LOL awesome... do you have to wear a man-bun to consume raw code?

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On