- Tasks
- Threads share memory. You have to make sure that memory accesses are atomic when it matters, using synchronization primitives.
- Processes by default have their own memory. In Unix, you have to use a "shared memory" API to communicate between processes. You can also use pipes and sockets.
- Synchronization
- Mutexes. Low-level primitive for making sure "critical sections" aren't interrupted by another scheduler giving control to another thread. Suppose two threads share some memory. This ensures thread A can finish its modification of the shared memory before thread B accesses the memory, and vice-versa. See the Xinu OS book.
- Semaphores. Another low-level primitive for signaling that something has been done, and waiting on it in another thread. Similar to mutexes, effectively protects shared memory and indicates "critical sections." See the Xinu OS book, Wikipedi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct A { | |
name: String | |
} | |
struct B { | |
name: String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OPENOCD ?= /usr/bin/openocd/ | |
OPENOCD_SCRIPTS ?= /usr/share/openocd/scripts | |
openocd: $(ELF) | |
$(OPENOCD) -s $(OPENOCD_SCRIPTS) \ | |
-f interface/stlink-v2-1.cfg \ | |
-f target/stm32l4x.cfg \ | |
-c "telnet_port 4444" \ | |
-c "gdb_port 3333" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implement a queue with 2 stacks . Your queue should have an enqueue and a | |
# dequeue function and it should be "first in first out" (FIFO). | |
# | |
# Optimize for the time cost of mmm function calls on your queue. These can be | |
# any mix of enqueue and dequeue calls. | |
# | |
# Assume you already have a stack implementation and it gives O(1) | |
# time push and pop. | |
class Stack(list): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a 32-bit decimal number, convert it to binary, reverse it, then print | |
# the reversed version in decimal. | |
def solution(n): | |
result = 0 | |
for i in range(32): | |
result |= ((n >> i) & 1) << (31 - i) | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Given a list of "passwords" for which e.g. "abc" and "cba" or "cat" and "tac" | |
# are not considered unique but "abc" and "bac" are considered unique, count the | |
# unique words in the list. | |
# | |
# Usage: python3 2.py < words.txt | |
import sys | |
from collections.abc import Set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Given a list of "passwords" for which e.g. "abc" and "cba" or "cat" and "tac" | |
; are not considered unique but "abc" and "bac" are considered unique, count the | |
; unique words in the list. | |
; | |
; Run it like this: `clojure 2.clj < words.txt` | |
(require 'clojure.string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options iwlwifi 11n_disable=1 | |
options iwlwifi swcrypto=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This is free and unencumbered software released into the public domain. | |
# | |
# Anyone is free to copy, modify, publish, use, compile, sell, or | |
# distribute this software, either in source code form or as a compiled | |
# binary, for any purpose, commercial or non-commercial, and by any | |
# means. | |
# | |
# In jurisdictions that recognize copyright laws, the author or authors |
NewerOlder