Blender freezes in multi-threaded tasks since recent rB98123ae91680, on windows - atomic ops issue? #48422

Closed
opened 2016-05-13 17:29:46 +02:00 by Denis Belov · 23 comments

System Information
Win 7x64, Nvidia GTX 580

Blender Version
broken: blender-2.77.0-git.b72aef9-AMD64
Working: blender-2.77.0-git.898d040-AMD64

Blender freezes while trying to do vertex snapping with subdivision modifier enabled both in object and edit mode.

  1. Create Suzanne
  2. Add Subsurface modifier, duplicate mesh
  3. Try to manipulate meshes with vertex snapping enabled

Sometimes i can reproduce this instantly, sometime not, so try open attached file, it freezes all the time.
bug.blend

**System Information** Win 7x64, Nvidia GTX 580 **Blender Version** broken: blender-2.77.0-git.b72aef9-AMD64 Working: blender-2.77.0-git.898d040-AMD64 Blender freezes while trying to do vertex snapping with subdivision modifier enabled both in object and edit mode. 1. Create Suzanne 2. Add Subsurface modifier, duplicate mesh 3. Try to manipulate meshes with vertex snapping enabled Sometimes i can reproduce this instantly, sometime not, so try open attached file, it freezes all the time. [bug.blend](https://archive.blender.org/developer/F310802/bug.blend)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @DenisBelov

Added subscriber: @DenisBelov

#48432 was marked as duplicate of this issue

#48432 was marked as duplicate of this issue

#48442 was marked as duplicate of this issue

#48442 was marked as duplicate of this issue

#48440 was marked as duplicate of this issue

#48440 was marked as duplicate of this issue

#48437 was marked as duplicate of this issue

#48437 was marked as duplicate of this issue

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This is caused by 98123ae916

This is caused by 98123ae916

Added subscriber: @mont29

Added subscriber: @mont29

Cannot reproduce that here… @ideasman42 you just opened the file and did some snapped transform in Object or Edit mode, and got the freeze?

Anyway, if this commit causes issues, it can be reverted, gave nearly no speed gain anyway…

Cannot reproduce that here… @ideasman42 you just opened the file and did some snapped transform in Object or Edit mode, and got the freeze? Anyway, if this commit causes issues, it can be reverted, gave nearly no speed gain anyway…

Added subscriber: @mano-wii

Added subscriber: @mano-wii

I don't like to revert optimizations (no matter how small) :(
@mont29 if the first time has not frozen, try again, there are times when it works.
(Just make the snap to vertices in object mode. Edit mode also freezes)

I don't like to revert optimizations (no matter how small) :( @mont29 if the first time has not frozen, try again, there are times when it works. (Just make the snap to vertices in object mode. Edit mode also freezes)

I tried it several times of course, with both release and debug builds. Am on linux though, not sure on which OS Campbell reproduced it.

I do found an error in new code that could create issues, committed a fix, please give it a try. :)

I tried it several times of course, with both release and debug builds. Am on linux though, not sure on which OS Campbell reproduced it. I do found an error in new code that could create issues, committed a fix, please give it a try. :)

ops, saying to "try again" I meant close and open Blender (but you also must have already tried this way).

At first, it seemed that was fixed. But the problem came back on the second try :( (no fix)

ops, saying to "try again" I meant close and open Blender (but you also must have already tried this way). At first, it seemed that was fixed. But the problem came back on the second try :( (no fix)

Still cannot reproduce at all…

Might be related to #48437, can you please try and see if you can reproduce it?

Still cannot reproduce at all… Might be related to #48437, can you please try and see if you can reproduce it?

Yes I can reproduce it.
And the race condition also occurs in the loop "while (UNLIKELY(previter != olditer)".

I found a strange thing - after the end of the loop execution, suddenly, out of nowhere, it runs again without passing by the expected sequence of the function.

(I do not understand this atomic thing however)

Yes I can reproduce it. And the race condition also occurs in the loop "while (UNLIKELY(previter != olditer)". I found a strange thing - after the end of the loop execution, suddenly, out of nowhere, it runs again without passing by the expected sequence of the function. (I do not understand this atomic thing however)

Grumph… atomic means the operation is done in 'a single step' from CPU point of view, i.e. you cannot have thread 1 start an atomic operation, then thread 2 modify one of its operands, then thread 1 finish the operation.

Those atomic ops are implemented in all modern CPUs, and are much cheaper than using regular thread synchronization primitives like mutex or spinlock.

That looping func is a way to perform an operation that does not exists in atomic primitives, idea is to:

  • read current value of the shared data we want to modify (32bit data, reading is assumed atomic, i.e. you cannot read part of the value, then get it changed by another thread, then read the remaining part).
  • do the operation and store its value in a local variable (this can take any amount of time, since it only uses local or read-only variables).
  • do an atomic CAS to set the shared variable we want to modify.
  • Repeat as long a value returned by CAS is not the same as the one we stored at the beginning (meaning the shared variable has been modified by another thread in-between).

The atomic CAS (compare and swap) compares the value of the data to modify with a given 'reference', only sets the former with the new value if it equals to the reference value, and then return the old value of modified data.

So in theory, this is perfectly safe and no deadlock should happen. Actually, there is no actual deadlock possible here, since there is no lock - I’d rather think of an inifite loop due to something messed up in msvc version of our atomic primitives.

I would suspect some stupid conversion mismatch between signed and unsigned integers (though afaik uint32 < INT_MAX should not be an issue here :| ).
Can you please try to replace line 76 of intern/atomic/intern/atomic_ops_msvc.h file with that one, and check again?

  	return InterlockedCompareExchange((long *)v, *(long *)(&_new), *(long *)(&old));
Grumph… atomic means the operation is done in 'a single step' from CPU point of view, i.e. you cannot have thread 1 start an atomic operation, then thread 2 modify one of its operands, then thread 1 finish the operation. Those atomic ops are implemented in all modern CPUs, and are much cheaper than using regular thread synchronization primitives like mutex or spinlock. That looping func is a way to perform an operation that does not exists in atomic primitives, idea is to: - read current value of the shared data we want to modify (32bit data, reading is assumed atomic, i.e. you cannot read part of the value, then get it changed by another thread, then read the remaining part). - do the operation and store its value in a local variable (this can take any amount of time, since it only uses local or read-only variables). - do an atomic CAS to set the shared variable we want to modify. - Repeat as long a value returned by CAS is not the same as the one we stored at the beginning (meaning the shared variable has been modified by another thread in-between). The atomic CAS (compare and swap) compares the value of the data to modify with a given 'reference', only sets the former with the new value if it equals to the reference value, and then return the old value of modified data. So in theory, this is perfectly safe and no deadlock should happen. Actually, there is no actual deadlock possible here, since there is no lock - I’d rather think of an inifite loop due to something messed up in msvc version of our atomic primitives. I would suspect some stupid conversion mismatch between signed and unsigned integers (though afaik uint32 < INT_MAX should not be an issue here :| ). Can you please try to replace line 76 of `intern/atomic/intern/atomic_ops_msvc.h` file with that one, and check again? ``` return InterlockedCompareExchange((long *)v, *(long *)(&_new), *(long *)(&old)); ```

(I'm still trying to understand all the explanation ...)

However did the change you requested (line 76 of atomic_ops_msvc.h), and the problem persists :(

(I'm still trying to understand all the explanation ...) However did the change you requested (line 76 of atomic_ops_msvc.h), and the problem persists :(

Guess I’ll have to go and debug this myself on my win VM (provided blender still runs on it), looks like our win atomics is broken somehow (unless I miss something else, maybe we'd need some kind of memory fence here, not sure why or where though)…

Guess I’ll have to go and debug this myself on my win VM (provided blender still runs on it), looks like our win atomics is broken somehow (unless I miss something else, maybe we'd need some kind of memory fence here, not sure why or where though)…

Added subscribers: @VertexPainter, @Ace_Dragon

Added subscribers: @VertexPainter, @Ace_Dragon
Bastien Montagne changed title from Blender freezes while trying to do vertex snapping with subdivision modifier enabled. to Blender freezes in multi-threaded tasks since recent rB98123ae91680, on windows - atomic ops issue? 2016-05-15 20:41:56 +02:00
Bastien Montagne self-assigned this 2016-05-15 20:41:56 +02:00

Added subscribers: @Clarkx, @MassimilianoPuliero

Added subscribers: @Clarkx, @MassimilianoPuliero

This issue was referenced by bb7da630ba

This issue was referenced by bb7da630bacf211d9caabdfbe12cdfaa31939a65

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#48422
No description provided.