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
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/types.h> | |
#include <time.h> | |
// New type definitions |
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
/* | |
* Demonstrate a minimal code to implement thread switching in user | |
* space | |
**/ | |
#include <ucontext.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <signal.h> | |
#include <sys/time.h> |
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
#include <signal.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdbool.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
bool running = true; | |
void sigHandler(int number) { |
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
use core::ffi::c_void; // FFI: Foreign Function Interface | |
use libc::{c_int, shmid_ds}; | |
use libc::{shmat, shmctl, shmdt, shmget}; | |
use libc::{IPC_PRIVATE, IPC_RMID, S_IRUSR, S_IWUSR}; | |
const FOO: usize = 4096; | |
fn main() { | |
println!("Hello, world!"); | |
let shm_ptr: *mut c_void; |
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
use nix::unistd::sleep; | |
use std::thread; | |
// Global variable | |
static mut SHARED_DATA: u8 = 5; | |
fn main() { | |
// Use lambda when the thread function takes arguments | |
let thr1 = thread::spawn(|| do_greeting3('a')); | |
let thr2 = thread::spawn(|| do_greeting3('b')); |
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
#include <iostream> | |
#include <unistd.h> | |
#include <thread> | |
using namespace std; | |
void do_greeting3(char arg); | |
//arguments:arg is an untyped pointer pointing to a character | |
// returns:a pointer to NULL | |
// side effects:prints a greeting |
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
// extern crate rand; | |
// use nix::unistd::sleep; | |
// use std::process; | |
use rand::Rng; | |
use std::thread; | |
fn main() { | |
// Use lambda when the thread function takes arguments | |
let thr1 = thread::spawn(|| do_greeting2(30)); | |
let thr2 = thread::spawn(|| do_greeting2(50)); |
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
// Compile with -lpthread flag | |
#include <thread> | |
#include <iostream> | |
#include <sys/types.h> | |
#include <unistd.h> | |
using namespace std; | |
/* Thread functions in C++ can take any number of args of any type */ | |
void do_greeting2 (int, 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
#include <pthread.h> | |
#include <errno.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void* do_greeting2 (void* arg); |
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
// Compile with -lpthread flag | |
#include <iostream> | |
#include <thread> | |
#include <unistd.h> | |
using namespace std; | |
void do_greeting(); | |
int main() { |