Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
1337JiveTurkey
Feb 17, 2005

Zombywuf posted:

It looks to me that x + 1 == y is the bit that fucks up because the object may change between each side of the equality operator being read. The empty synchronised block appears to be some sort of magical ward against it but as far as I'm aware it does basically nothing in this case. I'm not really up to date on Java though so maybe it does actually do something useful.

It's valid but offers very weak semantics. Namely any writes performed before the synchronized block in one thread will be visible to any reads after the synchronized block for the same object in another thread. Of course any subsequent writes may also be visible, and it doesn't guarantee that the writing thread will be the first to hit the block. If the reader hits first, then the conflict still happens.

Note that removing the synchronized(this){} block is simply turning it into an infinite loop since the thread checking the value never reassigns it, and the optimizer is perfectly free to never check again that the actual value in memory has changed.

edit: Also the object reference can't change between p.x+1 and p.y since it's a local variable, but the value of p.x or p.y could change.

1337JiveTurkey fucked around with this message at 21:32 on Aug 16, 2013

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
This really is surprising. I would have expected that the object needs to be fully constructed before the final assignment operation (currentPos =...) could be performed, but apparently that isn't the case with some JVM optimizations, and thinking about it a little I suppose it's not that surprising since doing so is effectively "safe" here as far as the runtime cares.

1337JiveTurkey
Feb 17, 2005

Volmarias posted:

This really is surprising. I would have expected that the object needs to be fully constructed before the final assignment operation (currentPos =...) could be performed, but apparently that isn't the case with some JVM optimizations, and thinking about it a little I suppose it's not that surprising since doing so is effectively "safe" here as far as the runtime cares.

Final fields will be initialized unless a reference to the object escapes within the constructor. That is, if you pass a this reference to another thread in the constructor, that thread can see an uninitialized value. On the other end of the lifecycle, the object will always be fully constructed when the finalizer is run, so you can count on that much. However strictly speaking if an object is determined to be unreachable then it can in principle be garbage collected and finalized immediately. If an instance method never references the object itself or any of its fields then the instance can even be garbage collected and finalized before the method has returned since it's unreachable. This can be prevented by synchronizing on the instance.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

1337JiveTurkey posted:

However strictly speaking if an object is determined to be unreachable then it can in principle be garbage collected and finalized immediately. If an instance method never references the object itself or any of its fields then the instance can even be garbage collected and finalized before the method has returned since it's unreachable. This can be prevented by synchronizing on the instance.

I get the feeling that someone has counted on this behavior not occurring, and you have dealt with the aftermath.

Honestly, the advice I've been given in the past has been to assume that because there's no guarantee of when the finalizer will be run after the object is viable for GC, or that it even WILL be run, to just not bother with them in the first place, something that I've found really isn't a big problem.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Volmarias posted:

This really is surprising. I would have expected that the object needs to be fully constructed before the final assignment operation (currentPos =...) could be performed, but apparently that isn't the case with some JVM optimizations, and thinking about it a little I suppose it's not that surprising since doing so is effectively "safe" here as far as the runtime cares.

Not just JVM optimizations, CPU-level optimizations can break this as well (unless you want to kill performance by having your compiler put memory barriers in what looks like single-threaded code).

Especially once you go outside of x86-land and its almost-strict memory ordering.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Jabor posted:

Not just JVM optimizations, CPU-level optimizations can break this as well (unless you want to kill performance by having your compiler put memory barriers in what looks like single-threaded code).

Especially once you go outside of x86-land and its almost-strict memory ordering.

Bingo... Just because the JVM (or CLR) promises not to reorder things doesn't mean poo poo to the CPU. Now that even your phone is multi-core, the phrase "concurrent" really loving means concurrent. The local CPU may never even see an inconsistent view but the thread may run on a different core that does. Don't be clever, just use synchronization primitives in a straightforward way. The number of times a profiler showed synchronization as the bottleneck compared to the number of times people claimed it was must be around 1:100.

Programs are meaninglessly executed by meaningless machines producing meaningless output exactly as designed. Concurrency is a great way to prove how little the computer adheres to your idea of what is/is not possible or logical.

Hughlander
May 11, 2005

Plorkyeran posted:

In the specific case of C and C++, this is because dependency management is terrible. In Python, Ruby, Javascript, Objective-C (and a bunch of other languages I haven't used for real projects), adding a new dependency consists of adding a single line to the config file and everything just works. Unsurprisingly, it's common to end up with small projects that use 30 simple single-purpose libraries.

In C++ I have to add poo poo to the configure script for each library (which may involve writing some custom autoconf macros), telling people where to get the library, describing how to build it (because Debian only has a 8-year-old version of it packaged, and some distros don't have it at all), and now the number of steps involved in building my application is greater than the acceptable maximum (one). Alternatively, I can spend two weeks trying to automate dependency fetching and end up with something that half-works but annoys all the people that want to use the system copies of libraries.

Or I could just spend a few days reinventing the wheel because it's less work than using the existing wheel.

You're conflating language, IDE, and Operating system there. How many Python modules have you tried to use on win32 that fail to install because gcc isn't in your path? Show me an Objective-C library running on that Debian system you mentioned working with a single line to a config file. Hell I had NodeJS libraries break because the npm guys one day randomly swapped LibraryName for LibraryName2 when you asked for LibraryName which used a totally different build system that wasn't compatible with my version of node. That was a great one to figure out since I had pinned the version of the library in requirements file.

Hughlander fucked around with this message at 15:39 on Aug 17, 2013

OnceIWasAnOstrich
Jul 22, 2006

To be fair that Python example is only true because it isn't pure Python, you are now compiling C.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Yes, oddly enough I factor things like what platform the code will be running on when picking a language to use for a project rather than trying to do things like use Objective-C on Debian.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Ender.uNF posted:

Bingo... Just because the JVM (or CLR) promises not to reorder things doesn't mean poo poo to the CPU. Now that even your phone is multi-core, the phrase "concurrent" really loving means concurrent. The local CPU may never even see an inconsistent view but the thread may run on a different core that does. Don't be clever, just use synchronization primitives in a straightforward way. The number of times a profiler showed synchronization as the bottleneck compared to the number of times people claimed it was must be around 1:100.

Programs are meaninglessly executed by meaningless machines producing meaningless output exactly as designed. Concurrency is a great way to prove how little the computer adheres to your idea of what is/is not possible or logical.

Right, the underlying problem is a lack of synchronization and thread safety, I'm just surprised at how this failed in particular.

Volmarias fucked around with this message at 18:10 on Aug 17, 2013

QuarkJets
Sep 8, 2008

We're setting up a data processing system that will takes files on a NAS, make copies of them, do some basic processing on their contents, and then push a result into a database. The software engineer wants to write this system in Python. The program manager (who is sort of a software programmer who eventually clawed his way into management) is forcing him to use MATLAB :reject:

evensevenone
May 12, 2001
Glass is a solid.
Demo it in Spyder and tell him its the new version of MATLAB.

EntranceJew
Nov 5, 2009

QuarkJets posted:

We're setting up a data processing system that will takes files on a NAS, make copies of them, do some basic processing on their contents, and then push a result into a database. The software engineer wants to write this system in Python. The program manager (who is sort of a software programmer who eventually clawed his way into management) is forcing him to use MATLAB :reject:

Can't somebody veto this terrible thing before it happens? Surely if you yell loudly enough at the right people you should be able to scare someone into putting a little more critical thought into it.

QuarkJets
Sep 8, 2008

EntranceJew posted:

Can't somebody veto this terrible thing before it happens? Surely if you yell loudly enough at the right people you should be able to scare someone into putting a little more critical thought into it.

Not happening; the project manager is actually from an outside company, they're a customer for the product. Ultimately they're purchasing whatever they tell us to make even if we recommend something else

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
What was the name of that weird bible type Linux OS that kind of generated random bits as a quote from god? It got posted here a couple months ago, but I can't remember it past that.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Master_Odin posted:

What was the name of that weird bible type Linux OS that kind of generated random bits as a quote from god? It got posted here a couple months ago, but I can't remember it past that.

I'm pretty sure it was LoseThos when the crazy guy who created it was posting around here.

He's changed the name about a dozen times since then, for reasons known only to C:/BIBLE.TXT.

Spatial
Nov 15, 2007

Temple OS. I don't think it's Linux though. The guy seems to have written it from scratch.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Spatial posted:

Temple OS. I don't think it's Linux though. The guy seems to have written it from scratch.

Yeah, it's been called losethos, sparrowos, templeos, etc. Dude's a crazy idiot in every sense, there's sort of this weird edge to his voice in his youtube ramblings, and he sucks at making operating systems too.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Cocoa Crispies posted:

Yeah, it's been called losethos, sparrowos, templeos, etc. Dude's a crazy idiot in every sense, there's sort of this weird edge to his voice in his youtube ramblings, and he sucks at making operating systems too.

Doesn't his "fully modern" operating system require a dual core and several gigs of RAM to push C64-era graphics because it does everything in (super slow) software?

Also it's programmed in Holy C.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Cocoa Crispies posted:

Yeah, it's been called losethos, sparrowos, templeos, etc. Dude's a crazy idiot in every sense, there's sort of this weird edge to his voice in his youtube ramblings, and he sucks at making operating systems too.

To be fair, he wrote a functional OS single-handledly. That's a pretty impressive feat even if it's done poorly and the author is a nutcase.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Yeah the general consensus between myself and everybody else I've shown those videos too was less "Hahaha holy poo poo what an idiot" and more "Wait he did what all by himself? And why all the Jesus?!"

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Ithaqua posted:

To be fair, he wrote a functional OS single-handledly. That's a pretty impressive feat even if it's done poorly and the author is a nutcase.

Not really. Undergrads do that poo poo, and don't even have ridiculous and wrong ideas about the usefulness of memory mapping, BIOS, VGA, and other features of commodity computers from the last thirty years. The guy's response to somebody criticizing the homemade PRNG he wrote for the babble generator he thinks is god was to paste a shitload of it into YOSPOS [insert joke about how nobody could tell the difference between it and regular yosposting] and get banned for being insane and somehow boring.

Crosscontaminant
Jan 18, 2007

The great bit for me is that he trumpets how hilariously insecure his operating system is because he designed it to be as much like his beloved Commodore as possible (even eschewing ASCII or Unicode in favour of "8-bit unsigned characters").

quote:

The main reason TempleOS is simple and beautiful is because it's ring-0-only and identity-mapped. Linux wants to be a secure, multi-user mainframe. That's the vision for Linux. That's why it has file permissions. The vision for TempleOS is a modern, 64-bit Commodore 64. The C64 was a home computer mostly used for games. It trained my generation how to program. It was simple, open and hackable. It was not networked. The games were not multimedia works of art, but generated programmatically with innocent, programmer (non-artist) quality graphics. It was simple and unsecure. If you don't have malware and you don't have bugs, protection just slows things down and makes the code complicated.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Edit: Derp, misread, nevermind.

seiken
Feb 7, 2005

hah ha ha

Crosscontaminant posted:

If you don't have malware and you don't have bugs, protection just slows things down and makes the code complicated.

To be fair, an operating system used by one person ever is unlikely to be plagued with malware.

biznatchio
Mar 31, 2001


Buglord

seiken posted:

To be fair, an operating system used by one person ever is unlikely to be plagued with malware.

You could make a compelling argument that an operating system used by one person ever is malware in its own right.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

seiken posted:

To be fair, an operating system used by one person ever is unlikely to be plagued with malware.

Also it can't get online, so there's that

Impotence
Nov 8, 2010
Lipstick Apathy

carry on then posted:

Also it's programmed in Holy C.

http://www.templeos.org/Wb/Demo/DateTime.html

Pilsner
Nov 23, 2002

Holy christ... literally.

Reminds me a bit of the A-Patch for Windows Messenger, written by a muslim.
code:
Praise be to God.

Changelog (1.43 build 23)

New: Added compatibility for Windows Live Messenger 2012 version 16.4.3508.0205

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I was looking through the source code to a huge, legacy classic ASP site a few jobs ago, and I found a page that had a weird name. I opened it up, and it was:

1) A large comment written in Hindi that was some sort of prayer
2) A form that allowed you to execute any arbitrary SQL command against the application's database. Where passwords were stored in plaintext. It was public-facing.

I promptly deleted the page from production and source control. My boss was horrified; the page was from a consulting firm that had written the original application ~10 years prior.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Jesus Christ, just shows that those kinds of horrors aren't limited to PHP

tef
May 30, 2004

-> some l-system crap ->
git config --global core.precomposeunicode true :shrek:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

tef posted:

git config --global core.precomposeunicode true :shrek:

I'm trying to find out what the point of that option is and I'm coming up empty. Though I have no trouble believing that an option called "pre-compose unicode" can be a pain. What's your story here?

1337JiveTurkey
Feb 17, 2005

pokeyman posted:

I'm trying to find out what the point of that option is and I'm coming up empty. Though I have no trouble believing that an option called "pre-compose unicode" can be a pain. What's your story here?

It sounds like it's referring to the form of normalization used. With Unicode there are often equivalent encodings for the same character which are semantically identical but retained to retain round-trip encoding for other character sets. Since a string can contain either, in order to tell if two strings are the same there needs to be some canonical form. NFD is the fully decomposed normal form (everything that can be formed using a base character and combining diacritics is written that way) while NFC is the fully* composed form after full decomposition. I'm not sure how it ties into git.

*For small values of fully.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

pokeyman posted:

I'm trying to find out what the point of that option is and I'm coming up empty. Though I have no trouble believing that an option called "pre-compose unicode" can be a pain. What's your story here?

Mac OS X does funky stuff with unicode in filenames to remain compatible with a dead OS nobody uses anymore. Linux doesn't, and some dead OS that people still use has always been a special case in Git.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Cocoa Crispies posted:

Mac OS X does funky stuff with unicode in filenames to remain compatible with a dead OS nobody uses anymore. Linux doesn't, and some dead OS that people still use has always been a special case in Git.
Decomposing all characters isn't particularly funky. Normalizing all filenames eliminates some dumb issues, and neither of the normalization forms are objectively superior to the other.

Zombywuf
Mar 29, 2008

Maybe the ultimate in multi-threaded debug printing bugs: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=44387

Crosscontaminant
Jan 18, 2007

I wrote this. I'm sorry.

code:
mod = {k: v for k, v in zip(range(-6, 7), map(operator.truediv, map(lambda x: 2 if x < 1 else x + 2, range(-6, 7)), map(lambda x: 2 if x < 1 else x + 2, range(6, -7, -1))))}

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Crosscontaminant posted:

I wrote this. I'm sorry.

code:
mod = {k: v for k, v in zip(range(-6, 7), map(operator.truediv, map(lambda x: 2 if x < 1 else x + 2, range(-6, 7)), map(lambda x: 2 if x < 1 else x + 2, range(6, -7, -1))))}

Python code:
from __future__ import division
mod = {k: v for k, v in ((x, (2 if x < 1 else x+2) / (2 if -x < 1 else -x+2)) for x in range(-6, 7))}

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



LOOK I AM A TURTLE posted:

Python code:
from __future__ import division
mod = {k: v for k, v in ((x, (2 if x < 1 else x+2) / (2 if -x < 1 else -x+2)) for x in range(-6, 7))}

Python code:
mod = {x: (max(0, x) + 2.0) / (max(0, -x) + 2.0) for x in range(-6, 7)}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply