Skip to content

Instantly share code, notes, and snippets.

View 0minus273's full-sized avatar

Marina Morozova 0minus273

View GitHub Profile
113 int i = 0;
114 int received = 0;
115 int sizenow = 4096;
116 int sizebefore = sizenow;
117 char *buffer = (char *) malloc(sizenow);
118 char *buf = buffer;
119 while ((received = read(sock, buf, 4096))>0)
120 {
121 i = i + received;
122 sizebefore = sizenow;
50 static bool
51 pack_str(struct whackpacker *wp, char **p)
52 {
53 const char *s = *p == NULL? "" : *p; /* note: NULL becomes ""! */
54 size_t len = strlen(s) + 1;
55
56 if (wp->str_roof - wp->str_next < (ptrdiff_t)len)
57 {
58 return FALSE; /* fishy: no end found */
59 }
@0minus273
0minus273 / well.c
Last active August 29, 2015 14:04
well.c
struct whack_message msg;
struct whackpacker wp;
//где whackpaker имеет вид:
struct whackpacker {
struct whack_message *msg;
unsigned char *str_roof;
unsigned char *str_next;
int n;
#!/bin/sh
# IPsec startup and shutdown script
#
### BEGIN INIT INFO
# Provides: ipsec
# Required-Start: $network $remote_fs $syslog $named
# Required-Stop: $syslog $remote_fs
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: Start Openswan IPsec at boot time
import java.util.concurrent;
public class Ex2q1fix {
private static class Peterson {
private final AtomicIntegerArray flag = new AtomicIntegerArray(2);
public volatile int victim;
public void lock() throws InterruptedException {
System.out.println("Aquiring lock for thread with id=" + threadLocalId.get());
@0minus273
0minus273 / gist:11320402
Created April 26, 2014 13:44
Peterson.java
public class Peterson {
public volatile boolean[] flag = new boolean[2];
public volatile int victim;
public void lock() {
int i = Integer.parseInt(Thread.currentThread().getName().substring(7)) - 1;
int j = 1 - i;
flag[j] = true;
victim = i;
while (flag[j] && victim == i) {}; // wait
}
@0minus273
0minus273 / gist:11320381
Created April 26, 2014 13:43
Ex2q1.java
//package mpp;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class Ex2q1 {
@0minus273
0minus273 / gist:10717203
Last active August 29, 2015 13:59
wtfiswrong.java
//package mcp;
public class outpit {
static int counter = 0;
public static void main(String[] args) throws InterruptedException {
if (args.length < 1) {
throw new IllegalArgumentException("Usage: Ex1q9 N");
}
Integer numberOfThreads = Integer.valueOf(args[0]);
public class myE {
static int counter = 0;
public static void main(String[] args) throws InterruptedException {
if (args.length < 1) {
throw new IllegalArgumentException("Usage: Ex1q9 N");
1 class Bouncer f
2 public static nal int DOWN = 0;
3 public static nal int RIGHT = 1;
4 public static nal int STOP = 2;
5 private boolean goRight = false;
6 private ThreadLocal<Integer> myIndex;
7 private int last = 1;
8 int visit () f
9 int i = myIndex.get();
10 last = i;