๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ป/CS

(8)
[์šด์˜์ฒด์ œ] Synchronization - 3. Spin lock๊ณผ Mutex lock, Mutex์™€ Semaphore mutex lock - lock์„ ์žก๊ธฐ ์œ„ํ•ด ์˜ค๋žœ ์‹œ๊ฐ„์„ ๊ธฐ๋‹ค๋ ค์•ผ ํ•  ๊ฒƒ ๊ฐ™์œผ๋ฉด ๋‹ค๋ฅธ ์ž‘์—…์„ ๋™์‹œ์— ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. - busy waiting ํ•˜์ง€ ๋ง๊ณ , blocking ๋˜์–ด ๊ธฐ๋‹ค๋ฆฌ์ž. - ์ž์›์„ ๋‹จ์‹œ๊ฐ„์— ์–ป์„ ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ๊ฒฝ์šฐ ์ฐจ๋ผ๋ฆฌ spin lock์ด ํšจ๊ณผ์ ์ด๋‹ค. context switching์— ๋” ํฐ ์ž์›์„ ๋‚ญ๋น„ํ•˜๊ฒŒ ๋  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋ฅผ ์ดˆ๋ž˜ํ•œ๋‹ค. spin lock - ๋ฌธ๋งฅ ๊ตํ™˜(context switching)์ด ์ผ์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค. - ๋‹ค๋ฅธ ์ž‘์—…์„ ๋™์‹œ์— ์ง„ํ–‰ํ•˜์ง€ ๋ชปํ•˜๊ณ  ์ง„์ž… ๊ฐ€๋Šฅํ•  ๋•Œ ๊นŒ์ง€ ๊ณ„์† ๊ธฐ๋‹ค๋ฆฌ๋Š” busy waiting ๋ฐฉ์‹์ด๋‹ค. - lock์„ ์žก์„ ๋•Œ ๊นŒ์ง€ ๋Š์ž„์—†๋Š” ๋ฌดํ•œ ๋ฃจํ”„๋ฅผ ํ†ตํ•ด critical section์— ์ง„์ž…์„ ์žฌ์‹œ๋„ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํ•˜๋‚˜์˜ ์Šค๋ ˆ๋“œ๊ฐ€ ๊ณ„์† CPU๋ฅผ ์ ์œ ํ•˜๊ณ  ์žˆ..
[์šด์˜์ฒด์ œ] Synchronization - 2 Spinlock : ์žก์œผ๋ ค๋Š” lock์ด avaliable ํ•ด ์งˆ ๋•Œ ๊นŒ์ง€ ๊ณ„์† ๋ฃจํ”„๋ฅผ ๋Œ๋ฉฐ ์ง„์ž…์„ ์žฌ์‹œ๋„ํ•œ๋‹ค. ์ด๋ฅธ๋ฐ” ๋ฐ”์˜๊ฒŒ ๊ธฐ๋‹ค๋ฆฌ๋Š” busy waiting์˜ ํ•œ ์ข…๋ฅ˜์ด๋‹ค. Busy waiting : lock์„ ์žก๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š๊ณ  ๊ณ„์†ํ•ด์„œ ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ฒฝ์šฐ. Sofrware-only Algorithm Peterson's Algorithm ๋™๊ธฐํ™” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์ฒ˜์Œ์œผ๋กœ ๊ณ ์•ˆ๋œ ๋ฐฉ๋ฒ• ์˜ค์ง ๋‘๊ฐœ์˜ context๋งŒ์ด ์กด์žฌํ•˜๋Š” ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•œ๋‹ค. ์ „์—ญ๋ณ€์ˆ˜ flag, turn ์„ ์–ธ flag: critical section์— ๋“ค์–ด๊ฐˆ ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋Š”์ง€, flag[0] = true; turn: ๋ˆ„๊ฐ€ critical section์— ๋“ค์–ด๊ฐˆ ์ฐจ๋ก€์ธ์ง€ ๋ฌธ์ œ์  ๋‘๊ฐœ์˜ context๋งŒ ์กด์žฌํ•˜๋Š” ์ƒํ™ฉ์—์„œ๋งŒ ๊ฐ€๋Šฅ ..
[์šด์˜์ฒด์ œ] Synchronization - 1 ํ•˜๋‚˜์˜ address space์— ์„œ๋กœ ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ๋“ค์ด ๋™์‹œ์— ์ ‘๊ทผํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. Race Condition ๋‘ ๊ฐœ ์ด์ƒ ํ”„๋กœ์„ธ์Šค/์Šค๋ ˆ๋“œ๊ฐ€ shared resource์— ๋™์‹œ์— concurrentํ•˜๊ฒŒ ์ ‘๊ทผํ•จ์œผ๋กœ์จ ๊ฒฐ๊ณผ ๊ฐ’์ด ํ™•์ • ๋˜์ง€๊ฐ€ ์•Š๊ณ , ๊ทธ๋•Œ ๊ทธ๋•Œ ์‹คํ–‰ํ•  ๋•Œ๋งˆ๋‹ค ์กฐ๊ธˆ์”ฉ ๋ฐ”๋€Œ๋Š” ํ˜„์ƒ ๋‘ ๊ฐœ ์ด์ƒ์˜ concurrent ํ•œ ํ”„๋กœ์„ธ์Šค, ์Šค๋ ˆ๋“œ๋“ค์ด ๊ณต์œ  ์ž์›์— ์ ‘๊ทผ ํ•  ๋•Œ ๋™๊ธฐํ™” ํ•ด๊ฒฐ ๊ณผ์ •์—†์ด ์ˆ˜ํ–‰ํ•˜๋Š” ์ƒํ™ฉ race condition์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ฒ• → synchronization Critical Section ์ฝ”๋“œ์—์„œ ๋‘๊ฐœ ์ด์ƒ์˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋™์‹œ์— ๋ฆฌ์†Œ์Šค๋ฅผ ์—…๋ฐ์ดํŠธ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ๊ฐ„. ๊ฐ ํ”„๋กœ์„ธ์Šค์—์„œ ๊ณต์œ  ๋ฐ์ดํ„ฐ์— ์ ‘๊ทผํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ ์ฝ”๋“œ ๋ถ€๋ถ„. ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์Šค๋ ˆ๋“œ๊ฐ€ ์ˆ˜ํ–‰๋˜๋Š” ํ”„๋กœ๊ทธ๋žจ์—์„œ ๊ฐ ํ”„๋กœ..
[์šด์˜์ฒด์ œ] Real-time System์ด๋ž€? Real-time Task : ์‹œ์Šคํ…œ์ด ์ฒ˜๋ฆฌํ•˜๋Š” ์ผ์ด deadline์ด ์กด์žฌํ•˜๊ฑฐ๋‚˜ ์‹œ๊ฐ„์— ๋Œ€ํ•ด์„œ ์–ด๋Š ์‹œ๊ฐ„ ๋‚ด๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ทธ๋Ÿฐ ๋ฅ˜์˜ specification์ด ์ •ํ•ด์ง€๋Š” ์ผ๋“ค. Real-time Task๋“ค์ด ์žˆ๋Š” System => Real-time System Soft real-time systems ex) linux real-time task ์™€ Non-real-time task๋“ค์ด ํ˜ผ์žฌ๋˜์–ด ์žˆ๋Š” ์ƒํ™ฉ์—์„œ, ์‹œ์Šคํ…œ์ด real-time task๋ฅผ ์กฐ๊ธˆ ๋” ์‹ ๊ฒฝ์จ์„œ ์ฒ˜๋ฆฌํ•ด ์ฃผ๊ธฐ๋Š” ํ•˜์ง€๋งŒ, ๋ฌด์กฐ๊ฑด deadline์— ๋งž์ถฐ์„œ ๋๋‚ด์ค„๊ฑฐ๋ผ๋Š” ๋ณด์žฅ์ด ์—†๋Š” ์‹œ์Šคํ…œ. real-time task๋ฅผ ์กฐ๊ธˆ ๋” ๊ณ ๋ ค ํ•˜๊ฒ ์œผ๋‚˜, 100ํผ ๋ณด์žฅ ๋ชปํ•จ. real-time์„ ์•„์˜ˆ ์ œ๊ณตํ•˜์ง€ ์•Š์ง„ ์•Š์Œ. Hard real-time s..
CS ์ฐธ๊ณ  https://github.com/WeareSoft/tech-interview GitHub - WeareSoft/tech-interview: ๐Ÿ™ tech interview :loudspeaker:๐Ÿ™ tech interview. Contribute to WeareSoft/tech-interview development by creating an account on GitHub. github.com https://github.com/WooVictory/Ready-For-Tech-Interview GitHub - WooVictory/Ready-For-Tech-Interview: ๐Ÿ’ป ์‹ ์ž… ๊ฐœ๋ฐœ์ž๋กœ์„œ ์ค€๋น„๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ์ง€์‹์„ ์ •๋ฆฌํ•˜๋Š” ๊ณต๊ฐ„ ๐Ÿ’ป ์‹ ์ž… ๊ฐœ๋ฐœ์ž๋กœ์„œ ์ค€๋น„๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ์ง€์‹์„ ์ •๋ฆฌํ•˜๋Š” ๊ณต๊ฐ„ ๐Ÿ‘จ‍๐Ÿ’ป. Con..
CS50_๋ฐฐ์—ด 1) ์ปดํŒŒ์ผ๋ง make๋‚˜ clang์„ ์‚ฌ์šฉํ•ด์„œ ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰ํ•  ๋•Œ ๊ฑฐ์น˜๋Š” ๋„ค๋‹จ๊ณ„ ์ „์ฒ˜๋ฆฌ # ์œผ๋กœ ์‹œ์ž‘๋˜๋Š” C ์†Œ์Šค ์ฝ”๋“œ๋Š” ์ „์ฒ˜๋ฆฌ๊ธฐ์—๊ฒŒ ์‹ค์งˆ์ ์ธ ์ปดํŒŒ์ผ์ด ์ด๋ฃจ์–ด์ง€๊ธฐ ์ „์— ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹คํ–‰ํ•˜๋ผ๊ณ  ์•Œ๋ ค์คŒ. ์˜ˆ๋ฅผ ๋“ค์–ด, #include๋Š” ์ „์ฒ˜๋ฆฌ๊ธฐ์—๊ฒŒ ๋‹ค๋ฅธ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ํฌํ•จ์‹œํ‚ค๋ผ๊ณ  ์•Œ๋ ค์คŒ. ํ”„๋กœ๊ทธ๋žจ์˜ ์†Œ์Šค ์ฝ”๋“œ์— #include ์™€ ๊ฐ™์€ ์ค„์„ ํฌํ•จํ•˜๋ฉด, ์ „์ฒ˜๋ฆฌ๊ธฐ๋Š” ์ƒˆ๋กœ์šด ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๋Š”๋ฐ ์ด ํŒŒ์ผ์€ ์—ฌ์ „ํžˆ C ์†Œ์Šค ์ฝ”๋“œ ํ˜•ํƒœ์ด๋ฉฐ stdio.h ํŒŒ์ผ์˜ ๋‚ด์šฉ์ด #include ๋ถ€๋ถ„์— ํฌํ•จ๋จ. ์ปดํŒŒ์ผ๋ง ์ปดํŒŒ์ผ๋Ÿฌ๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ํ”„๋กœ๊ทธ๋žจ์€ C ์ฝ”๋“œ๋ฅผ ์–ด์…ˆ๋ธ”๋ฆฌ์–ด๋ผ๋Š” ์ €์ˆ˜์ค€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ์ปดํŒŒ์ผ. ์–ด์…ˆ๋ธ”๋ฆฌ๋Š” C๋ณด๋‹ค ์—ฐ์‚ฐ์˜ ์ข…๋ฅ˜๊ฐ€ ํ›จ์”ฌ ์ ์ง€๋งŒ, ์—ฌ๋Ÿฌ ์—ฐ์‚ฐ๋“ค์ด ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜๋ฉด C์—์„œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๊ฒƒ๋“ค์„ ์ˆ˜ํ–‰. C ์ฝ”๋“œ๋ฅผ ์–ด์…ˆ..
CS50_C์–ธ์–ด 1) C๊ธฐ์ดˆ #include ๋Š” “stdio.h”๋ผ๋Š” ์ด๋ฆ„์˜ ํŒŒ์ผ์„ ์ฐพ์•„์„œ “printf” ํ•จ์ˆ˜์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์คŒ. ์šฐ๋ฆฌ๊ฐ€ ์ง์ ‘ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋Š” “์†Œ์Šค ์ฝ”๋“œ” ์ด๋ฅผ 2์ง„์ˆ˜๋กœ ์ž‘์„ฑ๋œ “๋จธ์‹  ์ฝ”๋“œ”๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ์ปดํ“จํ„ฐ๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ž‘์—…์„ ์ปดํŒŒ์ผ๋Ÿฌ๋ผ๋Š” ํ”„๋กœ๊ทธ๋žจ์ด ์ˆ˜ํ–‰ 2) ๋ฌธ์ž์—ด 3) ์กฐ๊ฑด๋ฌธ๊ณผ ๋ฃจํ”„ ๋ฐ์ดํ„ฐ ํƒ€์ž… bool: ๋ถˆ๋ฆฌ์–ธ ํ‘œํ˜„, (์˜ˆ) True, False, 1, 0, yes, no char: ๋ฌธ์ž ํ•˜๋‚˜ (์˜ˆ) 'a', 'Z', '?' string: ๋ฌธ์ž์—ด int: ํŠน์ • ํฌ๊ธฐ ๋˜๋Š” ํŠน์ • ๋น„ํŠธ๊นŒ์ง€์˜ ์ •์ˆ˜ (์˜ˆ) 5, 28, -3, 0 long: ๋” ํฐ ํฌ๊ธฐ์˜ ์ •์ˆ˜ float: ๋ถ€๋™์†Œ์ˆ˜์ ์„ ๊ฐ–๋Š” ์‹ค์ˆ˜ (์˜ˆ) 3.14, 0.0, -28.56 double: ๋ถ€๋™์†Œ์ˆ˜์ ์„ ํฌํ•จํ•œ ๋” ํฐ ์‹ค์ˆ˜ ..
CS50_์ปดํ“จํŒ… ์‚ฌ๊ณ  1. ์ปดํ“จํŒ… ์‚ฌ๊ณ  1) 2์ง„๋ฒ• ์ปดํ“จํ„ฐ์—๋Š” ์˜ค์ง 0๊ณผ 1๋กœ๋งŒ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. 0๊ณผ 1๋กœ๋งŒ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์„ 2์ง„๋ฒ•์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ปดํ“จํ„ฐ๋Š” ์˜ค๋กœ์ง€ 0๊ณผ 1๋งŒ์œผ๋กœ ์ˆซ์ž ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ธ€์ž, ์‚ฌ์ง„, ์˜์ƒ, ์†Œ๋ฆฌ ๋“ฑ์„ ์ €์žฅ ์ง„๋ฒ•์—์„œ๋Š” ๋‘ ๊ฐœ์˜ ์ˆซ์ž๋งŒ ์žˆ์œผ๋ฏ€๋กœ ๊ฐ ์ž๋ฆฌ์ˆ˜๊ฐ€ 2์˜ ๊ฑฐ๋“ญ์ œ๊ณฑ์„ ์˜๋ฏธ ๋น„ํŠธ 2) ์ •๋ณด์˜ ํ‘œํ˜„ ๋ฌธ์ž๋ฅผ ์ˆซ์ž๋กœ ํ‘œํ˜„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ •ํ•ด์ง„ ์•ฝ์†(ํ‘œ์ค€) : ASCII CODE 3) ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž…๋ ฅ(input)์—์„œ ๋ฐ›์€ ์ž๋ฃŒ๋ฅผ ์ถœ๋ ฅ(output)ํ˜•ํƒœ๋กœ ๋งŒ๋“œ๋Š” ์ฒ˜๋ฆฌ ๊ณผ์ • ์ž…๋ ฅ๊ฐ’์„ ์ถœ๋ ฅ๊ฐ’์˜ ํ˜•ํƒœ๋กœ ๋ฐ”๊พธ๊ธฐ ์œ„ํ•ด ์–ด๋–ค ๋ช…๋ น๋“ค์ด ์ˆ˜ํ–‰๋˜์–ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ๊ทœ์น™๋“ค์˜ ์ˆœ์„œ์  ๋‚˜์—ด4 4) ์Šคํฌ๋ž˜์น˜: ๊ธฐ์ดˆ 5) ์Šคํฌ๋ž˜์น˜: ์‹ฌํ™”