Programming Thread

Started by the-pi-guy, Mar 13, 2016, 10:39 PM

previous topic - next topic

0 Members and 2 Guests are viewing this topic.

Go Down

Legend

I Learned ++int is not thread safe. Seems I had two different threads doing ++int and --int on the same value at the exact same time and only one or the other would be applied.

Explains why the glitch I was noticing was so rare.

the-pi-guy

Someone actually made a huge vocab list from this other textbook I have.  Which has ~7200 words.  This is going to be huge.  :o

I Learned ++int is not thread safe. Seems I had two different threads doing ++int and --int on the same value at the exact same time and only one or the other would be applied.

Explains why the glitch I was noticing was so rare.
In my second programming class, there was a little bit about multithreading. 
We had to use "synchronized", a keyword in Java.  Otherwise if we assigned one thread to add 2500 to a number, and another thread to add 2500 to the same number, it usually wouldn't quite make it up to 5000. 
Both threads would access the number, and change it at the same time.  Which would cause it to only go up by 1 instead of 2. 

"synchronized" made sure that the other thread would wait for the thread to finish accessing it. 

Although it was funny, because when the teacher tried demonstrating it, without the keyword (so he was expecting something like 4800 something.)  It actually got really lucky and made it all the way to 5000, 2 out of the first 5 times.  Only 2 times it actually worked. 

Legend

Someone actually made a huge vocab list from this other textbook I have.  Which has ~7200 words.  This is going to be huge.  :o

In my second programming class, there was a little bit about multithreading.  
We had to use "synchronized", a keyword in Java.  Otherwise if we assigned one thread to add 2500 to a number, and another thread to add 2500 to the same number, it usually wouldn't quite make it up to 5000.  
Both threads would access the number, and change it at the same time.  Which would cause it to only go up by 1 instead of 2.  

"synchronized" made sure that the other thread would wait for the thread to finish accessing it.  

Although it was funny, because when the teacher tried demonstrating it, without the keyword (so he was expecting something like 4800 something.)  It actually got really lucky and made it all the way to 5000, 2 out of the first 5 times.  Only 2 times it actually worked.  
Yeah in C# it's called "lock." I'm needing my code to run as fast as possible so I tried to design it with as few locked parts as possible.

However I'm probably still going to switch it over to the GPU. I'm rendering 100s of thousands of lines and issuing the draw call can take so much CPU time. Instead I figure I could store the lines in a compute buffer and render them in a more direct fashion.

the-pi-guy

I was thinking about my raspberry Pi project.  And I think right now I'm going to scale down the hardware part of it.  I don't think I really have the art skills to build the case that I'd want.  Instead I think I can probably make something decent, just by making a case for the screen and the Pi itself (Actually found one made, that I plan on paying Tacos to make for me.)  

It'll be a bit lame, but I think it'll be fairly cool and get some actual usage out of it.  Then I could use the battery to connect to the Pi outside of the case.  And have a controller of some sort.  I don't like having to carry around 3 parts, but it'll be something at least...  Maybe just have a little bag or something to make it more manageable.

I also want to look into making some sort of OS for it.  I have that class coming up, and it'd be really cool to have something substantial to show for it.  

the-pi-guy


Legend


Legend

"A different error message! Finally some progress!"

the-pi-guy


Legend


the-pi-guy

That's kinda awesome!
It's awesome and horrifying at the same time.

Legend


Legend


the-pi-guy

Have a virtual machine so I can program C with all the special features.  

the-pi-guy

It's been pretty cool learning how an OS works. How it manages processes and threads.

Legend

It's been pretty cool learning how an OS works. How it manages processes and threads.
How good is windows in regards to that stuff?

Go Up