• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:52
CEST 04:52
KST 11:52
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL50Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
The GOAT ranking of GOAT rankings The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Esports World Cup 2025 - Final Player Roster How does the number of casters affect your enjoyment of esports?
Tourneys
RSL: Revival, a new crowdfunded tournament series [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo) FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Player “Jedi” cheat on CSL Help: rep cant save Flash Announces Hiatus From ASL BGH Auto Balance -> http://bghmmr.eu/ [ASL19] Finals Recap: Standing Tall
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Trading/Investing Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread NBA General Discussion Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 612 users

The Big Programming Thread - Page 806

Forum Index > General Forum
Post a Reply
Prev 1 804 805 806 807 808 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-28 03:46:06
November 28 2016 03:42 GMT
#16101
edit 2:

okay i edited the original
i dunno what I was doing before
it makes sense now right?
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 04:22:26
November 28 2016 04:17 GMT
#16102
Was trying to think up a way to explain this without just giving you the solution, but its all syntax so hopefully you will look through it and learn something. If you have any questions about why I did things this way I can answer.

+ Show Spoiler +
import java.util.Random;

public class MathWithMultipleThreads {

private static Random random = new Random();
private static int HEIGHT = 1000;
private static int WIDTH = 1000;

private static double[][] makeArray(int height, int width) {
double[][] answer = new double[height][width];
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
answer[row][col] = random.nextDouble();
}
}
return answer;
}

public static void main(String[] args) throws InterruptedException {
double[][] array = makeArray(HEIGHT, WIDTH);
long start = System.nanoTime();

Thread[] threads = new Thread[HEIGHT];

for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));
threads[i].start();
}

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}

long end = System.nanoTime();
System.out.println((end - start) / 1000000000.0);
}
}

public class ProcessRow implements Runnable {

double[] row;

public ProcessRow(double[] row) {
this.row = row;
}

@Override
public void run() {
for (int i = 0; i < row.length; i++){
row[i] = Math.sqrt(row[i]);
}
}
}


As an additional exercise, change my code so that it only makes 4 threads, but still finds the squareroot of all the data properly. I'd say that has more practical use if nothing else.
I'll always be your shadow and veil your eyes from states of ain soph aur.
ZigguratOfUr
Profile Blog Joined April 2012
Iraq16955 Posts
November 28 2016 04:19 GMT
#16103
Nietzsche once said that "State is the name of the coldest of all cold monsters." Does that mean Nietzsche was a functional programmer?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-28 04:35:58
November 28 2016 04:27 GMT
#16104


//declare an array of threads, intialize it to height elements
Thread[] threads = new Thread[HEIGHT];

//go through each element and say that the thread contains ProcessRow
//is this accurate? And can you only do this because ProcessRow is "runnable" ?
for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));

//you also start the thread (it does run() at this point? )
threads[i].start();
}

//what does join do exactly? makes it so the program stops executing until whatever threads are executing have all caught up?

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}





thanks btw. exactly what I needed. Not as confusing as I expected.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-11-28 04:32:10
November 28 2016 04:31 GMT
#16105
Are you just taking a general intro to programming course travis?

Or is all of this part of a program and your questions are from a variety of courses?

I've never taken a single course that covered this much variety in material.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 28 2016 04:34 GMT
#16106
It's a single course. "Object Oriented Programming 2"
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 12:54:53
November 28 2016 04:37 GMT
#16107
On November 28 2016 13:27 travis wrote:


//declare an array of threads, intialize it to height elements
Thread[] threads = new Thread[HEIGHT];

//go through each element and say that the thread contains ProcessRow
//is this accurate? And can you only do this because ProcessRow is "runnable" ?
for (int i = 0; i < HEIGHT; i++) {
threads[i] = new Thread(new ProcessRow(array[i]));

//you also start the thread (it does run() at this point? )
threads[i].start();
}

//what does join do exactly? makes it so the program stops executing until whatever threads are executing have all //caught up?

for (int i = 0; i < HEIGHT; i++) {
threads[i].join();
}



thanks btw. exactly what I needed. Not as confusing as I expected.


1. as specified in problem statement

2. We're creating all the threads in this step. Each element of threads is one of the threads and the index happens to coincide nicely with each index of array we're processing. Thread has a constructor which takes a Runnable as a parameter. I've always seen Thread extended instead of implementing Runnable personally, but this works.

3. I could/should have called run() in this step. It does the same thing though.

4. Join blocks until the thread is finished processing. We ensure that each thread has finished its math with the join. I'm not sure how much you know about CPUs, processes, threads and the operating system, but I also lack the expertise to explain it well. I'd say its highly questionable to learn about threading without any knowledge of these topics though.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
November 28 2016 06:30 GMT
#16108
On November 28 2016 13:19 ZigguratOfUr wrote:
Nietzsche once said that "State is the name of the coldest of all cold monsters." Does that mean Nietzsche was a functional programmer?


Nietzsche was talking in terms of state as a country though
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
November 28 2016 07:16 GMT
#16109
--- Nuked ---
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 08:01 GMT
#16110
On November 28 2016 10:24 Manit0u wrote:
I think that the first thing you should work on is structuring your data properly:


tree->left->right->left->left


Holy hell...

Also, may I ask why do you want to introduce closures in C? C is not a functional language and trying to make it so isn't going to help you.

Edit: I assume you have seen this already?

The course I'm doing this in is 'advanced compilers', the closure is how we've been taught to introduce function calls

As for the data structure, that tree->left->right stuff is me navigating the abstract syntax tree to get the required nodes (e.g. In that example the current position in the tree is at the base of a function definition and that navigates to either the location of the function name, base of the function body or arguments) generated from the inputted c program, the parser was provided code so I can't make changes.

I am however quite overwhelmed with the course and the way I've done things is definitely not the best way
11/5/14 CATACLYSM | The South West's worst Falco main
emperorchampion
Profile Blog Joined December 2008
Canada9496 Posts
November 28 2016 08:02 GMT
#16111
Schrodinger's bug
TRUEESPORTS || your days as a respected member of team liquid are over
icystorage
Profile Blog Joined November 2008
Jollibee19343 Posts
November 28 2016 08:05 GMT
#16112
I had a job interview last week (I already have a job) for a mid level position. During the technical interview Q&A, I only answered around 40% of the total questions, is that normal?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 08:18 GMT
#16113
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered
11/5/14 CATACLYSM | The South West's worst Falco main
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2016-11-28 09:51:22
November 28 2016 09:45 GMT
#16114
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...
Time is precious. Waste it wisely.
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
November 28 2016 09:47 GMT
#16115
is there a windows equivalent to "command &" in linux? like run program and return to console
Age of Mythology forever!
Manit0u
Profile Blog Joined August 2004
Poland17243 Posts
Last Edited: 2016-11-28 09:54:46
November 28 2016 09:53 GMT
#16116
On November 28 2016 18:47 mantequilla wrote:
is there a windows equivalent to "command &" in linux? like run program and return to console



start /B command


http://www.computerhope.com/starthlp.htm
Time is precious. Waste it wisely.
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 10:13 GMT
#16117
On November 28 2016 18:45 Manit0u wrote:
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

Show nested quote +
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...


Ah that clears that up then
11/5/14 CATACLYSM | The South West's worst Falco main
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2016-11-28 12:55:19
November 28 2016 12:50 GMT
#16118
I'll always be your shadow and veil your eyes from states of ain soph aur.
RoomOfMush
Profile Joined March 2015
1296 Posts
November 28 2016 15:22 GMT
#16119
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered

The standard way is to implement Runnable. Extending Thread is possible but doesnt give you any benefits. Thread does not have any protected methods or fields. The idea behind implementing Runnable is separation of concerns. The Thread class takes care of all the complicated stuff and the runnable defines the behavior like a Strategy pattern.

On November 28 2016 18:45 Manit0u wrote:
Interesting read about JS: http://bonsaiden.github.io/JavaScript-Garden/

They point out some interesting pitfalls you can run into.

Show nested quote +
On November 28 2016 17:18 Targe wrote:
Also I have a java question, why would you ever extend thread instead of implementing runnable?

Always wondered


Thread already implements Runnable. The thing is, it comes with plenty of methods already defined so that you don't have to do that yourself (Runnable only has the run() prototype, so no start, stop, suspend, join etc.)...

You should not use the stop() or suspend() methods on Threads in java. There was even talk about removing them from Java 8 (by having them always throw exceptions) and breaking backwards compatibility. Thats how bad they are.
Targe
Profile Blog Joined February 2012
United Kingdom14103 Posts
November 28 2016 16:01 GMT
#16120
yeah runnable was how i learned to implement threads when i had to learn java i dont think ive ever extended thread
11/5/14 CATACLYSM | The South West's worst Falco main
Prev 1 804 805 806 807 808 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
HSC 27: Groups C
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
NeuroSwarm 391
Nina 228
CosmosSc2 48
StarCraft: Brood War
Aegong 116
Zeus 42
NaDa 39
Icarus 9
Dota 2
monkeys_forever122
League of Legends
JimRising 961
Super Smash Bros
hungrybox732
Other Games
summit1g8847
shahzam1227
ViBE260
Mew2King81
Organizations
Other Games
BasetradeTV96
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki43
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift6397
• Jankos1614
• masondota2645
Upcoming Events
RSL Revival
7h 8m
herO vs SHIN
Reynor vs Cure
OSC
10h 8m
WardiTV European League
13h 8m
Scarlett vs Percival
Jumy vs ArT
YoungYakov vs Shameless
uThermal vs Fjant
Nicoract vs goblin
Harstem vs Gerald
FEL
13h 8m
Korean StarCraft League
1d
CranKy Ducklings
1d 7h
RSL Revival
1d 7h
FEL
1d 13h
RSL Revival
2 days
FEL
2 days
[ Show More ]
BSL: ProLeague
2 days
Dewalt vs Bonyth
Replay Cast
3 days
Sparkling Tuna Cup
4 days
The PondCast
5 days
Replay Cast
5 days
RSL Revival
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.