<commit_before>#include <Interrupted.h>
#include <Tasks.h>

#define MAX	5

Semaphore forks[MAX];
static byte ids = 1;
static byte leds[] = { LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8 };

void eating(byte id, byte weight) {
	Serial.print("Philosopher ");
	Serial.print(id);
	Serial.print(" eats: ");
	Serial.println(weight);

	digitalWrite(leds[id], HIGH);

	delay(500);
	Tasks::ready(Tasks::current());
	Tasks::reschedule();

	digitalWrite(leds[id], LOW);
}

class Philosopher: public Task<60> {
public:
	void setup() {
		_id = ids++;
	}

	void loop() {
		forks[_id - 1].wait();
		forks[_id].wait();

		eating(_id, _w++);

		forks[_id - 1].signal();
		forks[_id].signal();
	}

private:
	byte _id, _w;
};

Philosopher philosophers[MAX-1];

void setup() {
	Serial.begin(9600);
	Tasks::init();
	for (int i = 0; i < MAX; i++) {
		forks[i].signal();
		pinMode(leds[i], OUTPUT);
	}
	for (int i = 0; i < MAX-1; i++)
		Tasks::start(philosophers[i]);
}

void loop() {
	static byte weight;

	forks[0].wait();
	forks[MAX-1].wait();

	eating(0, weight++);

	forks[0].signal();
	forks[MAX-1].signal();
}<commit_msg>use non-blocking task sleep<commit_after>#include <Interrupted.h>
#include <Tasks.h>

#define MAX	5

Semaphore forks[MAX];
static byte ids = 1;
static byte leds[] = { LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8 };

void eating(byte id, byte weight) {
	Serial.print("Philosopher ");
	Serial.print(id);
	Serial.print(" eats: ");
	Serial.println(weight);

	digitalWrite(leds[id], HIGH);

	Tasks::delay(500);

	digitalWrite(leds[id], LOW);
}

class Philosopher: public Task<50> {
public:
	void setup() {
		_id = ids++;
	}

	void loop() {
		forks[_id - 1].wait();
		forks[_id].wait();

		eating(_id, _w++);

		forks[_id - 1].signal();
		forks[_id].signal();
	}

private:
	byte _id, _w;
};

Philosopher philosophers[MAX-1];

void setup() {
	Serial.begin(9600);

	Tasks::init();
	Tasks::set_idle_handler(timer_sleep);
	for (int i = 0; i < MAX; i++) {
		forks[i].signal();
		pinMode(leds[i], OUTPUT);
	}
	for (int i = 0; i < MAX-1; i++)
		Tasks::start(philosophers[i]);
}

void loop() {
	static byte weight;

	forks[0].wait();
	forks[MAX-1].wait();

	eating(0, weight++);

	forks[0].signal();
	forks[MAX-1].signal();
}
{'fraction_non_alphanumeric': 0.20540540540540542, 'fraction_numerical': 0.02702702702702703, 'mean_word_length': 4.313397129186603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3854202', 'n_tokens_mistral': 998, 'n_tokens_neox': 911, 'n_words': 200}