• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:36
CEST 03:36
KST 10:36
  • 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
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Chinese SC2 server to reopen; live all-star event in Hangzhou17Weekly Cups (Oct 13-19): Clem Goes for Four2BSL Team A vs Koreans - Sat-Sun 16:00 CET7Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)81
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8) Weekly Cups (Oct 13-19): Clem Goes for Four Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (March 17-23): Clem Bounces Back
Tourneys
Tenacious Turtle Tussle RSL Season 3 Qualifier Links and Dates $1,200 WardiTV October (Oct 21st-31st) SC2's Safe House 2 - October 18 & 19 INu's Battles #13 - ByuN vs Zoun
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
SnOw's Awful Building Placements vs barracks BSL Team A vs Koreans - Sat-Sun 16:00 CET Is there anyway to get a private coach? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion
Tourneys
[Megathread] Daily Proleagues 300$ 3D!Community Brood War Super Cup #4 [ASL20] Semifinal B Azhi's Colosseum - Anonymous Tournament
Strategy
BW - ajfirecracker Strategy & Training Current Meta Roaring Currents ASL final [I] Funny Protoss Builds/Strategies
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Dawn of War IV ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine The Chess Thread Russo-Ukrainian War Thread Men's Fashion Thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Series you have seen recently... [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Sabrina was soooo lame on S…
Peanutsc
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1854 users

The Big Programming Thread - Page 806

Forum Index > General Forum
Post a Reply
Prev 1 804 805 806 807 808 1032 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
Poland17390 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
Jollibee19350 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
Poland17390 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
Poland17390 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 1032 Next
Please log in or register to reply.
Live Events Refresh
Tenacious Turtle Tussle
23:00
Biweekly #34
CranKy Ducklings133
LiquipediaDiscussion
OSC
16:00
Masters Cup #150 Qual 1-2
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft434
Livibee 166
CosmosSc2 109
ProTech106
Nathanias 99
StarCraft: Brood War
Artosis 716
Light 168
NaDa 57
Purpose 4
Dota 2
monkeys_forever681
LuMiX1
League of Legends
JimRising 606
Super Smash Bros
hungrybox609
Other Games
summit1g8598
C9.Mang0312
Maynarde132
ViBE125
Trikslyr60
Organizations
Other Games
gamesdonequick1379
Counter-Strike
PGL107
Other Games
BasetradeTV35
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Hupsaiya 68
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift5228
Other Games
• Scarra1576
Upcoming Events
The PondCast
8h 24m
OSC
10h 24m
WardiTV Invitational
1d 9h
Online Event
1d 14h
RSL Revival
2 days
RSL Revival
2 days
WardiTV Invitational
2 days
Afreeca Starleague
3 days
Snow vs Soma
Sparkling Tuna Cup
3 days
WardiTV Invitational
3 days
[ Show More ]
CrankTV Team League
3 days
RSL Revival
3 days
Wardi Open
4 days
CrankTV Team League
4 days
Replay Cast
5 days
WardiTV Invitational
5 days
CrankTV Team League
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
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

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
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.