const resources = createGraph({
nodes: [
{ id: 'thread1', data: { type: 'thread' } },
{ id: 'thread2', data: { type: 'thread' } },
{ id: 'lock1', data: { type: 'lock' } },
{ id: 'lock2', data: { type: 'lock' } },
],
edges: [
// thread1 holds lock1, wants lock2
{ id: '1', sourceId: 'lock1', targetId: 'thread1' },
{ id: '2', sourceId: 'thread1', targetId: 'lock2' },
// thread2 holds lock2, wants lock1
{ id: '3', sourceId: 'lock2', targetId: 'thread2' },
{ id: '4', sourceId: 'thread2', targetId: 'lock1' },
],
});
const cycles = getCycles(resources);
if (cycles.length > 0) {
console.error('Potential deadlock detected!');
cycles.forEach(cycle => {
const entities = [cycle.source.id, ...cycle.steps.map(s => s.node.id)];
console.error('Deadlock cycle:', entities.join(' -> '));
});
}